ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/utils/residentMem.c
Revision: 2028
Committed: Tue Feb 15 06:17:03 2005 UTC (19 years, 4 months ago) by gezelter
Content type: text/plain
File size: 839 byte(s)
Log Message:
bug fix for null termination

File Contents

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