-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_Process.cpp
31 lines (31 loc) · 1017 Bytes
/
class_Process.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
#include "class_Process.h"
#include <fstream>
#include <iostream>
#include <string>
void Process::find_name() {
std::string pid_string = std::to_string(this->process_pid);
std::string path = "/proc/" + pid_string + "/stat";
std::ifstream stat_file(path);
if (!stat_file.is_open()) {
std::cerr << "Not able to open file and find the name of: " << pid_string << std::endl;
return;
}
std::string name = "";
char c;
bool name_found = false;
while (stat_file.get(c)) {
if (!name_found) {
if (c == '(') {
name_found = true;
}
} else {
if (c == ')') {
this->process_name = name;
break;
}
name += c;
}
}
stat_file.close();
return;
}