| 6 | namespace KittyMemoryEx |
| 7 | { |
| 8 | std::string getProcessName(pid_t pid) |
| 9 | { |
| 10 | if (pid <= 0) |
| 11 | return ""; |
| 12 | |
| 13 | char filePath[256] = {0}; |
| 14 | snprintf(filePath, sizeof(filePath), "/proc/%d/cmdline", pid); |
| 15 | |
| 16 | errno = 0; |
| 17 | FILE *fp = fopen(filePath, "r"); |
| 18 | if (!fp) |
| 19 | { |
| 20 | KITTY_LOGD("Couldn't open cmdline file %s, error=%s", filePath, strerror(errno)); |
| 21 | return ""; |
| 22 | } |
| 23 | |
| 24 | char cmdline[128] = {0}; |
| 25 | fgets(cmdline, sizeof(cmdline), fp); |
| 26 | fclose(fp); |
| 27 | return cmdline; |
| 28 | } |
| 29 | |
| 30 | std::vector<pid_t> getProcessIDs(const std::string &processName) |
| 31 | { |
no outgoing calls
no test coverage detected