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

Comparing projects/cms/source/host/ihost-perl/plugins/linux/linux.c (file contents):
Revision 1.9 by pajs, Tue Apr 23 14:22:35 2002 UTC vs.
Revision 1.13 by tdb, Sat May 18 18:15:56 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * Copyright (C) 2000-2002 i-scream
4 + *
5 + * This program is free software; you can redistribute it and/or
6 + * modify it under the terms of the GNU General Public License
7 + * as published by the Free Software Foundation; either version 2
8 + * of the License, or (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 + */
19 +
20   #include <stdio.h>
21   #include <stdlib.h>
22   #include "ukcprog.h"
# Line 8 | Line 27
27   #include <utmp.h>
28   #include <pwd.h>
29   #include <mntent.h>
30 + #include <dirent.h>
31 + #include <limits.h>
32  
33   int die() {
34      exit (1);
# Line 248 | Line 269 | void cpustats() {
269   }
270  
271   void processStats() {
272 <    int sleeping=-1;
272 >    int sleeping=0;
273      int zombie=0;
274      int stopped=0;
275      int running=0;
276      int nousers=0;
277      char *line;
278 <    char *line_p;
278 >    char *line_ptr;
279      struct utmp *entry;
280 <    
280 >    DIR *procdir;
281 >    struct dirent *procent;
282 >    char fname[_POSIX_PATH_MAX];
283      FILE *f;
284 <    
285 <    if((f=popen("/bin/ps -Al" , "r")) == NULL) {
286 <        errf("Failed to get process stats (%m)");
287 <        die();
284 >    
285 >    chdir("/proc");
286 >    if((procdir=opendir(".")) == NULL){
287 >      errf("Failed to open proc (%m)");
288 >      exit(1);
289      }
266    
267    while((line=fpgetline(f)) != NULL) {
290  
291 <      line_p=line;
292 <      for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
293 <      line_p=strchr(line_p, ' ');
294 <      for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
295 <      if (line_p==NULL) abort();
296 <      /* Ok, we should now be at the state :) .. */
297 <      if (*line_p=='S') sleeping++;
298 <      if (*line_p=='R') running++;
299 <      if (*line_p=='Z') zombie++;
300 <      if (*line_p=='T') stopped++;
291 >    while((procent = readdir(procdir)) != NULL){
292 >      if(atoi(procent->d_name) == 0) continue;
293 >      strncpy(fname, procent->d_name, _POSIX_PATH_MAX-7);
294 >      strcat(fname, "/status");
295 >
296 >      if((f=fopen(fname, "r")) == NULL){
297 >         errf("Failed to open process stat (%m)");
298 >         exit(1);
299 >      }
300 >    
301 >      while((line=fpgetline(f)) != NULL){
302 >         if(strncasecmp(line,"State:",6)==0) break;
303 >      }
304 >
305 >      line_ptr=line;
306 >      for(;*line_ptr++ != '\t';);
307 >    
308 >
309 >      if(*line_ptr=='R') running++;
310 >      if(*line_ptr=='S') sleeping++;
311 >      if(*line_ptr=='Z') zombie++;
312 >      if(*line_ptr=='T') stopped++;
313 >      if(*line_ptr=='D') stopped++;
314 >
315      }
316 <    
317 <    if((pclose(f)) == -1) {
282 <        errf("Failed to close process stats (%m)");
283 <        die();
284 <    }
285 <    
316 >    closedir(procdir);
317 >
318      printf("packet.users.list");
319      
320      while((entry=getutent()) != NULL) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines