ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/examples/process_snapshot.c
(Generate patch)

Comparing projects/libstatgrab/examples/process_snapshot.c (file contents):
Revision 1.6 by tdb, Sun Apr 4 23:57:33 2004 UTC vs.
Revision 1.10 by ats, Thu Apr 8 13:16:04 2004 UTC

# Line 1 | Line 1
1   /*
2 < * i-scream central monitoring system
2 > * i-scream libstatgrab
3   * http://www.i-scream.org
4   * Copyright (C) 2000-2004 i-scream
5   *
# Line 26 | Line 26
26   #include <unistd.h>
27  
28   int main(){
29 <        proc_state_t *ps;
30 <        int ps_size;
31 <        int x;
29 >        sg_process_stats *ps;
30 >        int ps_size;
31 >        int x;
32          char *state = NULL;
33  
34          /* Initialise statgrab */
35 <        statgrab_init();
35 >        sg_init();
36  
37          /* Drop setuid/setgid privileges. */
38 <        if (statgrab_drop_privileges() != 0) {
38 >        if (sg_drop_privileges() != 0) {
39                  perror("Error. Failed to drop privileges");
40                  return 1;
41          }
42  
43 <        ps_size = get_proc_snapshot(&ps);
43 >        ps = sg_get_process_stats(&ps_size);
44  
45 <        if(ps_size < 0){
45 >        if(ps == NULL){
46                  fprintf(stderr, "Failed to get process snapshot\n");
47                  exit(1);
48          }
49  
50 +        qsort(ps, ps_size, sizeof *ps, sg_process_compare_pid);
51 +
52          printf("%5s %5s %5s %5s %5s %5s %5s %6s %6s %9s %-10s %-4s %-8s %-20s %s\n",
53                  "pid", "ppid", "pgid", "uid", "euid", "gid", "egid", "size", "res", "time", "cpu", "nice", "state", "name", "title");
54  
55 <        for(x=0;x<ps_size;x++){
55 >        for(x=0;x<ps_size;x++){
56                  switch (ps->state) {
57 <                case RUNNING:
57 >                case SG_PROCESS_STATE_RUNNING:
58                          state = "RUNNING";
59                          break;
60 <                case SLEEPING:
60 >                case SG_PROCESS_STATE_SLEEPING:
61                          state = "SLEEPING";
62                          break;
63 <                case STOPPED:
63 >                case SG_PROCESS_STATE_STOPPED:
64                          state = "STOPPED";
65                          break;
66 <                case ZOMBIE:
66 >                case SG_PROCESS_STATE_ZOMBIE:
67                          state = "ZOMBIE";
68                          break;
69 <                case UNKNOWN:
69 >                case SG_PROCESS_STATE_UNKNOWN:
70 >                default:
71                          state = "UNKNOWN";
72                          break;
73                  }
# Line 76 | Line 79 | int main(){
79                          (int)ps->time_spent, (float)ps->cpu_percent,
80                          (int)ps->nice, state,
81                          ps->process_name, ps->proctitle);
82 <                ps++;
83 <        }
82 >                ps++;
83 >        }
84          return 0;
85   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines