static void *outstat(void *arg)
{
-
char *sline = NULL;
char *pline = NULL;
char *mtline = NULL;
FILE *pmstat;
FILE *tf = fopen("/sys/devices/system/cpu/present","r");
int tmp, ncpu;
- char *pidname;
+ char *statmname;
+ char *statname;
long psize = sysconf(_SC_PAGESIZE);
struct statvfs fstat;
exit(1);
}
+ if (asprintf(&statmname, "/proc/%d/statm", pid) == -1) {
+ perror("asprintf");
+ exit(1);
+ }
- if (asprintf(&pidname, "/proc/%d/statm", pid) == -1) {
+ if (asprintf(&statname, "/proc/%d/stat", pid) == -1) {
perror("asprintf");
exit(1);
}
- pmstat = fopen(pidname, "r");
+ pmstat = fopen(statmname, "r");
if (pmstat == NULL) {
perror("open /proc/$pid/statm");
exit(1);
}
- pidname[strlen(pidname) - 1] = 0;
- pstat = fopen(pidname, "r");
+ pstat = fopen(statname, "r");
if (pstat == NULL) {
perror("open /proc/$pid/stat");
exit(1);
}
- free(pidname);
+
+ free(statmname);
+ free(statname);
while(1) {
char *stats[5];
return 0;
}
-