-
-
Save tiagovignatti/7a6c5d31a03dd34536f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
struct smaps_sizes { | |
int Pss; | |
int Rss; | |
}; | |
int main(const int argc, const char **argv) | |
{ | |
const char *filename = argv[1]; | |
FILE *file = fopen(filename, "r"); | |
struct smaps_sizes sizes; | |
memset(&sizes, 0, sizeof sizes); | |
if (!file) { | |
perror(filename); | |
return 1; | |
} | |
char line [BUFSIZ]; | |
while (fgets(line, sizeof line, file)) | |
{ | |
char substr[32]; | |
int n; | |
if (sscanf(line, "%31[^:]: %d", substr, &n) == 2) | |
{ | |
if (strcmp(substr, "Pss") == 0) { sizes.Pss += n; } | |
else if (strcmp(substr, "Rss") == 0) { sizes.Rss += n; } | |
} | |
} | |
fclose(file); | |
printf("Pss %d\n", sizes.Pss); | |
printf("Rss %d\n", sizes.Rss); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment