forked from udacity/CppND-System-Monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcess.h
85 lines (73 loc) · 1.95 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
#pragma once
#include <string>
#include "ProcessParser.h"
#include "util.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;
float cpu;
string mem;
float upTime;
public:
Process(string pid){
this->pid = pid;
this->user = ProcessParser::getProcUser(pid);
this->mem = ProcessParser::getVmSize(pid);
this->cmd = ProcessParser::getCmd(pid);
this->upTime = ProcessParser::getProcUpTime(pid);
this->cpu = ProcessParser::getCpuPercent(pid);
}
void setPid(int pid);
string getPid()const;
string getUser()const;
string getCmd()const;
float getCpu()const;
string getMem()const;
float getUpTime()const;
string getProcess();
};
void Process::setPid(int pid){
this->pid = pid;
}
string Process::getPid()const {
return this->pid;
}
string Process::getCmd()const {
return this->cmd;
}
float Process::getCpu()const {
return this->cpu;
}
string Process::getUser()const {
return this->user;
}
float Process::getUpTime()const {
return this->upTime;
}
string Process::getMem()const {
return this->mem;
}
string Process::getProcess(){
if(!ProcessParser::isPidExisting(this->pid))
return "";
mem = ProcessParser::getVmSize(pid);
upTime = ProcessParser::getProcUpTime(pid);
cpu = ProcessParser::getCpuPercent(pid);
stringstream out;
out << setprecision(2) << fixed;
out << setw(6) << right << pid << " "
<< setw(14) << left << user.substr(0,14) << " "
<< setw(7) << right << cpu << " "
<< setw(15) << right << mem << " "
<< setw(9) << right << Util::convertToTime((long)(upTime)) << " "
<< setw(30) << left << cmd.substr(0,50);
return out.str();
//return (pid + " " + user + " " + mem + " " + cpu + " " + upTime + " " + cmd.substr(0,30));
}