diff options
-rw-r--r-- | procps/ps.c | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/procps/ps.c b/procps/ps.c index fcb605a6e..aa408604a 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -49,14 +49,12 @@ static const int TERMINAL_WIDTH = 79; /* not 80 in case terminal has linefo | |||
49 | */ | 49 | */ |
50 | 50 | ||
51 | typedef struct proc_s { | 51 | typedef struct proc_s { |
52 | char | 52 | char cmd[16]; /* basename of executable file in call to exec(2) */ |
53 | cmd[16]; /* basename of executable file in call to exec(2) */ | 53 | int ruid; /* real only (sorry) */ |
54 | int | 54 | int pid; /* process id */ |
55 | ruid, /* real only (sorry) */ | 55 | int ppid; /* pid of parent process */ |
56 | pid, /* process id */ | 56 | char state; /* single-char code for process state (S=sleeping) */ |
57 | ppid; /* pid of parent process */ | 57 | unsigned int vmsize; /* size of process as far as the vm is concerned */ |
58 | char | ||
59 | state; /* single-char code for process state (S=sleeping) */ | ||
60 | } proc_t; | 58 | } proc_t; |
61 | 59 | ||
62 | 60 | ||
@@ -87,6 +85,8 @@ static void parse_proc_status(char *S, proc_t * P) | |||
87 | tmp = strstr(S, "State"); | 85 | tmp = strstr(S, "State"); |
88 | sscanf(tmp, "State:\t%c", &P->state); | 86 | sscanf(tmp, "State:\t%c", &P->state); |
89 | 87 | ||
88 | P->pid = 0; | ||
89 | P->ppid = 0; | ||
90 | tmp = strstr(S, "Pid:"); | 90 | tmp = strstr(S, "Pid:"); |
91 | if (tmp) | 91 | if (tmp) |
92 | sscanf(tmp, "Pid:\t%d\n" "PPid:\t%d\n", &P->pid, &P->ppid); | 92 | sscanf(tmp, "Pid:\t%d\n" "PPid:\t%d\n", &P->pid, &P->ppid); |
@@ -94,13 +94,21 @@ static void parse_proc_status(char *S, proc_t * P) | |||
94 | error_msg("Internal error!"); | 94 | error_msg("Internal error!"); |
95 | 95 | ||
96 | /* For busybox, ignoring effective, saved, etc. */ | 96 | /* For busybox, ignoring effective, saved, etc. */ |
97 | P->ruid = 0; | ||
97 | tmp = strstr(S, "Uid:"); | 98 | tmp = strstr(S, "Uid:"); |
98 | if (tmp) | 99 | if (tmp) |
99 | sscanf(tmp, "Uid:\t%d", &P->ruid); | 100 | sscanf(tmp, "Uid:\t%d", &P->ruid); |
100 | else | 101 | else |
101 | error_msg("Internal error!"); | 102 | error_msg("Internal error!"); |
102 | 103 | ||
103 | 104 | P->vmsize = 0; | |
105 | tmp = strstr(S, "VmSize:"); | ||
106 | if (tmp) | ||
107 | sscanf(tmp, "VmSize:\t%d", &P->vmsize); | ||
108 | #if 0 | ||
109 | else | ||
110 | error_msg("Internal error!"); | ||
111 | #endif | ||
104 | } | 112 | } |
105 | 113 | ||
106 | extern int ps_main(int argc, char **argv) | 114 | extern int ps_main(int argc, char **argv) |
@@ -131,7 +139,7 @@ extern int ps_main(int argc, char **argv) | |||
131 | terminal_width = win.ws_col - 1; | 139 | terminal_width = win.ws_col - 1; |
132 | #endif | 140 | #endif |
133 | 141 | ||
134 | printf(" PID Uid Stat Command\n"); | 142 | printf(" PID Uid VmSize Stat Command\n"); |
135 | while ((entry = readdir(dir)) != NULL) { | 143 | while ((entry = readdir(dir)) != NULL) { |
136 | if (!isdigit(*entry->d_name)) | 144 | if (!isdigit(*entry->d_name)) |
137 | continue; | 145 | continue; |
@@ -150,7 +158,10 @@ extern int ps_main(int argc, char **argv) | |||
150 | if (file == NULL) | 158 | if (file == NULL) |
151 | continue; | 159 | continue; |
152 | i = 0; | 160 | i = 0; |
153 | len = printf("%5d %-8s %c ", p.pid, uidName, p.state); | 161 | if(p.vmsize == 0) |
162 | len = printf("%5d %-8s %c ", p.pid, uidName, p.state); | ||
163 | else | ||
164 | len = printf("%5d %-8s %6d %c ", p.pid, uidName, p.vmsize, p.state); | ||
154 | while (((c = getc(file)) != EOF) && (i < (terminal_width-len))) { | 165 | while (((c = getc(file)) != EOF) && (i < (terminal_width-len))) { |
155 | i++; | 166 | i++; |
156 | if (c == '\0') | 167 | if (c == '\0') |
@@ -235,8 +246,10 @@ extern int ps_main(int argc, char **argv) | |||
235 | if (*uidName == '\0') | 246 | if (*uidName == '\0') |
236 | sprintf(uidName, "%ld", info.euid); | 247 | sprintf(uidName, "%ld", info.euid); |
237 | 248 | ||
238 | len = printf("%5d %-8s %c ", info.pid, uidName, info.state); | 249 | if(p.vmsize == 0) |
239 | 250 | len = printf("%5d %-8s %c ", p.pid, uidName, p.state); | |
251 | else | ||
252 | len = printf("%5d %-8s %6d %c ", p.pid, uidName, p.vmsize, p.state); | ||
240 | if (strlen(info.command_line) > 1) { | 253 | if (strlen(info.command_line) > 1) { |
241 | for( j=0; j<(sizeof(info.command_line)-1) && j < (terminal_width-len); j++) { | 254 | for( j=0; j<(sizeof(info.command_line)-1) && j < (terminal_width-len); j++) { |
242 | if (*(info.command_line+j) == '\0' && *(info.command_line+j+1) != '\0') { | 255 | if (*(info.command_line+j) == '\0' && *(info.command_line+j+1) != '\0') { |