ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/ihost-perl/plugins/freebsd/freebsd.c
(Generate patch)

Comparing projects/cms/source/host/ihost-perl/plugins/freebsd/freebsd.c (file contents):
Revision 1.5 by pajs, Thu Mar 28 17:46:52 2002 UTC vs.
Revision 1.6 by pajs, Thu Mar 28 18:16:21 2002 UTC

# Line 241 | Line 241 | void systemStats(){
241    
242   }
243  
244 + void processStats(){
245 +  int sleeping=-1;
246 +  int zombie=0;
247 +  int stopped=0;
248 +  int running=0;
249 +  char *line;
250 +  char *line_p;
251 +  
252 +  FILE *f;
253 +
254 +  if((f=popen("/bin/ps -ax" , "r")) == NULL) {
255 +    errf("Failed to get process stats (%m)");
256 +    die();
257 +  }
258 +
259 +  while((line=fpgetline(f)) != NULL) {
260 +    line_p=line;
261 +    for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
262 +    line_p=strchr(line_p, ' ');
263 +    for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
264 +    line_p=strchr(line_p, ' ');
265 +    for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
266 +    if (line_p==NULL) abort();
267 +
268 +    if (*line_p=='S') sleeping++;
269 +    if (*line_p=='I') sleeping++;
270 +    if (*line_p=='R') running++;
271 +    if (*line_p=='D') running++;
272 +    if (*line_p=='Z') zombie++;
273 +    if (*line_p=='T') stopped++;
274 +    if (*line_p=='J') running++;
275 +
276 +  }
277 +
278 +  if((pclose(f)) != 0) {
279 +    errf("Failed to close process stats (%m)");
280 +    die();
281 +  }
282 +  
283 +  printf("packet.processes.sleeping %d\n",sleeping);
284 +  printf("packet.processes.cpu %d\n",running);
285 +  printf("packet.processes.zombie %d\n",zombie);
286 +  printf("packet.processes.stopped %d\n", stopped);
287 +  printf("packet.processes.total %d\n", (sleeping+running+zombie+stopped));
288 +
289 +
290 + }
291 +
292 +
293   int main(){
294    uid=getuid();
295    euid=geteuid();
# Line 263 | Line 312 | int main(){
312    loadStats();
313    userStats();
314    systemStats();
315 +  processStats();
316    exit(0);
317   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines