1 |
gezelter |
340 |
#include <config.h> |
2 |
|
|
#include <string.h> |
3 |
|
|
#include <stdio.h> |
4 |
|
|
|
5 |
gezelter |
343 |
#define to_string( s ) # s |
6 |
|
|
#define STR_DEFINE(t, s) t = to_string(s) |
7 |
|
|
|
8 |
|
|
|
9 |
gezelter |
340 |
double residentMem () { |
10 |
|
|
|
11 |
|
|
FILE* procresults; |
12 |
|
|
char buf[150]; |
13 |
|
|
char* foo; |
14 |
|
|
long int myRSS, totRSS; |
15 |
gezelter |
342 |
char pscommand[150]; |
16 |
gezelter |
343 |
char* psPath; |
17 |
gezelter |
340 |
|
18 |
gezelter |
343 |
STR_DEFINE(psPath, PSCOMMAND ); |
19 |
gezelter |
340 |
|
20 |
gezelter |
343 |
strncpy(pscommand, psPath, strlen(psPath)); |
21 |
|
|
|
22 |
gezelter |
340 |
#if PSTYPE == BSD |
23 |
|
|
strcat(pscommand, " ax -o rss"); |
24 |
|
|
#else |
25 |
|
|
strcat(pscommand, " -ef -o rss"); |
26 |
|
|
#endif |
27 |
|
|
|
28 |
|
|
procresults = popen(pscommand, "r"); |
29 |
|
|
|
30 |
|
|
totRSS = 0; |
31 |
|
|
while (!feof(procresults)) { |
32 |
|
|
fgets( buf, 150, procresults); |
33 |
|
|
if (!strcmp(buf, " RSS")) continue; |
34 |
|
|
|
35 |
|
|
foo = strtok(buf, " ,;\t"); |
36 |
|
|
myRSS = atoi(foo); |
37 |
|
|
totRSS += myRSS; |
38 |
|
|
} |
39 |
|
|
pclose(procresults); |
40 |
|
|
|
41 |
|
|
return(totRSS); |
42 |
|
|
|
43 |
|
|
} |