| 94 | } |
| 95 | |
| 96 | std::vector<pid_t> getAllThreads(pid_t pid) |
| 97 | { |
| 98 | std::vector<pid_t> tids; |
| 99 | if (pid <= 0) |
| 100 | return tids; |
| 101 | |
| 102 | char filePath[256] = {0}; |
| 103 | snprintf(filePath, sizeof(filePath), "/proc/%d/task", pid); |
| 104 | |
| 105 | errno = 0; |
| 106 | DIR *dir = opendir(filePath); |
| 107 | if (!dir) |
| 108 | { |
| 109 | KITTY_LOGD("Couldn't open %s, error=%s", filePath, strerror(errno)); |
| 110 | return tids; |
| 111 | } |
| 112 | |
| 113 | dirent *entry = nullptr; |
| 114 | while ((entry = readdir(dir)) != nullptr) |
| 115 | { |
| 116 | if (entry->d_name[0] == '.') |
| 117 | continue; |
| 118 | |
| 119 | int entry_tid = atoi(entry->d_name); |
| 120 | if (entry_tid > 0) |
| 121 | { |
| 122 | tids.push_back(entry_tid); |
| 123 | } |
| 124 | } |
| 125 | closedir(dir); |
| 126 | return tids; |
| 127 | } |
| 128 | |
| 129 | bool ProcStatus::parse(const std::string &path, ProcStatus *out) |
| 130 | { |