/
Process.h
90 lines (76 loc) · 2.01 KB
/
Process.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef PROCESS_H
#define PROCESS_H
#include <string>
#include "ProcessParser.h"
using namespace std;
/*
Basic class for Process representation
It contains relevant attributes as shown below
*/
class Process {
private:
string pid;
string user;
string cmd;
string cpu;
string mem;
string upTime;
public:
Process(string pid){
this->pid = pid;
this->user = ProcessParser::getProcUser(pid);
//TODOs:
//complete for mem
this->mem = ProcessParser::getVmSize(pid);
//complete for cmd
this->cmd = ProcessParser::getCmd(pid);
//complete for upTime
this->upTime = ProcessParser::getProcUpTime(pid);
//complete for cpu
this->cpu = ProcessParser::getCpuPercent(pid);
}
//void setPid(int pid);
string getPid()const;
string getUser()const;
string getCmd()const;
int getCpu()const;
int getMem()const;
string getUpTime()const;
string getProcess();
};
// not using the setPid func
//void Process::setPid(int pid){
// this->pid = to_string(pid);
//}
string Process::getPid()const {
return this->pid;
}
string Process::getUser()const {
return this->user;
}
string Process::getCmd()const {
return this->cmd;
}
int Process::getMem()const {
return stoi(this->mem);
}
int Process::getCpu()const {
return stoi(this->cpu);
}
string Process::getUpTime()const {
return this->upTime;
}
string Process::getProcess(){
if(!ProcessParser::isPidExisting(this->pid))
return "";
this->mem = ProcessParser::getVmSize(this->pid);
this->upTime = ProcessParser::getProcUpTime(this->pid);
this->cpu = ProcessParser::getCpuPercent(this->pid);
return (this->pid + " " //TODO: finish the string! this->user + " "+ mem...cpu...upTime...;
+ this->user + " "
+ this->mem.substr(0,5) + " "
+ this->cpu.substr(0,5) + " "
+ this->upTime.substr(0,5) + " "
+ this->cmd.substr(0,10) + "... ");
}
#endif