MCPcopy Create free account
hub / github.com/MJx0/KittyMemoryEx / getProcessID

Function getProcessID

KittyMemoryEx/KittyMemoryEx.cpp:61–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59 }
60
61 pid_t getProcessID(const std::string &processName)
62 {
63 if (processName.empty())
64 return 0;
65
66 pid_t pid = 0;
67
68 errno = 0;
69 DIR *dir = opendir("/proc/");
70 if (!dir)
71 {
72 KITTY_LOGD("Couldn't open /proc/, error=%s", strerror(errno));
73 return pid;
74 }
75
76 dirent *entry = nullptr;
77 while ((entry = readdir(dir)) != nullptr)
78 {
79 if (entry->d_name[0] == '.')
80 continue;
81
82 int entry_pid = atoi(entry->d_name);
83 if (entry_pid > 0)
84 {
85 if (processName == getProcessName(entry_pid))
86 {
87 pid = entry_pid;
88 break;
89 }
90 }
91 }
92 closedir(dir);
93 return pid;
94 }
95
96 std::vector<pid_t> getAllThreads(pid_t pid)
97 {

Callers 2

mainFunction · 0.85
mainFunction · 0.85

Calls 1

getProcessNameFunction · 0.85

Tested by

no test coverage detected