This commit is contained in:
zy
2023-11-26 22:51:58 -05:00
parent be5f004df0
commit 998752bccd
2 changed files with 0 additions and 40 deletions

View File

@@ -1,40 +0,0 @@
#include <fstream>
#include <map>
#include <string>
class pid_cmdline pid_cmdline;
class pid_cmdline {
private:
std::map<int, std::string> cmdlines;
public:
void clear(void);
std::string& get_pid_cmdline(int pid);
};
static string unknow_symbol("UNKNOWN");
void pid_cmdline::clear(void) { cmdlines.clear(); }
std::string& pid_cmdline::get_pid_cmdline(int pid) {
if (cmdlines.count(pid) == 0) {
int i;
char buf[255];
char file[255];
std::fstream ifs;
snprintf(file, sizeof(file), "/proc/%d/cmdline", pid);
ifs.open(file, ios::binary | ios::in);
ifs.getline(buf, 255);
for (i = 0; i < ifs.gcount() && i < 255; i++) {
if (buf[i] < ' ') {
buf[i] = ' ';
}
}
cmdlines[pid] = buf;
}
return cmdlines[pid];
}

View File