| 26 | |
| 27 | |
| 28 | bool MemStat::Stat(pid_t pid) { |
| 29 | char fileName[256]; |
| 30 | if (pid == 0) { |
| 31 | strcpy(fileName, "/proc/self/statm"); |
| 32 | } else { |
| 33 | snprintf(fileName, sizeof(fileName), "/proc/%d/statm", pid); |
| 34 | } |
| 35 | |
| 36 | FILE *file = fopen(fileName, "r"); |
| 37 | if (file) { |
| 38 | if (0 == fscanf(file, "%lu %lu %lu %lu %lu %lu %lu", &size, &resident, &share, &text, &lib, &data, &dt)) { |
| 39 | ; |
| 40 | } |
| 41 | fclose(file); |
| 42 | return true; |
| 43 | } |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | |
| 48 | } // namespace utils |