1 |
gezelter |
340 |
#include <config.h> |
2 |
|
|
#include <string.h> |
3 |
|
|
#include <stdio.h> |
4 |
gezelter |
345 |
#include <stdlib.h> |
5 |
|
|
#ifdef __sgi |
6 |
|
|
#include <unistd.h> |
7 |
|
|
#endif |
8 |
gezelter |
340 |
|
9 |
gezelter |
345 |
/* |
10 |
|
|
* returns an estimate of the resident memory size in kB |
11 |
|
|
*/ |
12 |
tim |
963 |
RealType residentMem () { |
13 |
gezelter |
340 |
|
14 |
|
|
FILE* procresults; |
15 |
|
|
char buf[150]; |
16 |
|
|
char* foo; |
17 |
|
|
long int myRSS, totRSS; |
18 |
gezelter |
342 |
char pscommand[150]; |
19 |
gezelter |
343 |
char* psPath; |
20 |
gezelter |
340 |
|
21 |
gezelter |
343 |
STR_DEFINE(psPath, PSCOMMAND ); |
22 |
gezelter |
344 |
|
23 |
tim |
564 |
|
24 |
gezelter |
344 |
strncpy(pscommand, psPath, strlen(psPath)+1); |
25 |
gezelter |
340 |
|
26 |
gezelter |
345 |
#ifdef PSTYPE_IS_BSD |
27 |
gezelter |
340 |
strcat(pscommand, " ax -o rss"); |
28 |
|
|
#else |
29 |
gezelter |
345 |
#ifdef PSTYPE_IS_POSIX |
30 |
gezelter |
340 |
strcat(pscommand, " -ef -o rss"); |
31 |
gezelter |
345 |
#else |
32 |
|
|
printf("Unknown ps syntax!\n"); |
33 |
gezelter |
340 |
#endif |
34 |
gezelter |
345 |
#endif |
35 |
gezelter |
340 |
|
36 |
gezelter |
344 |
printf("doing %s\n", pscommand); |
37 |
|
|
|
38 |
gezelter |
340 |
procresults = popen(pscommand, "r"); |
39 |
|
|
|
40 |
|
|
totRSS = 0; |
41 |
|
|
while (!feof(procresults)) { |
42 |
|
|
fgets( buf, 150, procresults); |
43 |
|
|
if (!strcmp(buf, " RSS")) continue; |
44 |
|
|
|
45 |
|
|
foo = strtok(buf, " ,;\t"); |
46 |
|
|
myRSS = atoi(foo); |
47 |
|
|
totRSS += myRSS; |
48 |
|
|
} |
49 |
|
|
pclose(procresults); |
50 |
|
|
|
51 |
gezelter |
345 |
#ifdef __sgi |
52 |
tim |
564 |
|
53 |
|
|
|
54 |
gezelter |
345 |
totRSS *= getpagesize() / 1024; |
55 |
|
|
#endif |
56 |
|
|
|
57 |
tim |
564 |
|
58 |
tim |
357 |
totRSS *= 1024; |
59 |
gezelter |
340 |
return(totRSS); |
60 |
|
|
|
61 |
|
|
} |