-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.cpp
57 lines (44 loc) · 1.76 KB
/
system.cpp
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
#include <unistd.h>
#include <cstddef>
#include <set>
#include <string>
#include <vector>
#include <functional>
#include "process.h"
#include "processor.h"
#include "system.h"
#include "linux_parser.h"
using std::set;
using std::size_t;
using std::string;
using std::vector;
// TODO: Return the system's CPU
Processor& System::Cpu() { return cpu_; }
// Return a container composed of the system's processes
vector<Process>& System::Processes()
{
processes_.clear();
vector<int> list_pids = LinuxParser::Pids();
for(int pid : list_pids)
{
Process process(pid, LinuxParser::User(pid), LinuxParser::Command(pid),
LinuxParser::CpuUtilization(pid), LinuxParser::Ram(pid), LinuxParser::UpTime(pid));
processes_.push_back(process);
}
// I have taken ideas from below link to sort the list of Process objects
// https://stackoverflow.com/questions/1380463/sorting-a-vector-of-custom-objects
std::sort(processes_.begin(), processes_.end(), std::greater<Process>());
return processes_;
}
// Return the system's kernel identifier (string)
std::string System::Kernel() { return LinuxParser::Kernel(); }
// Return the system's memory utilization
float System::MemoryUtilization() { return LinuxParser::MemoryUtilization(); }
// Return the operating system name
std::string System::OperatingSystem() { return LinuxParser::OperatingSystem(); }
// Return the number of processes actively running on the system
int System::RunningProcesses() { return LinuxParser::RunningProcesses(); }
// Return the total number of processes on the system
int System::TotalProcesses() { return LinuxParser::TotalProcesses(); }
// Return the number of seconds since the system started running
long int System::UpTime() { return LinuxParser::UpTime(); }