Patch from Cliff L. Biffle <cbiffle@safety.net> to display memory
usage in the ps listing
This commit is contained in:
41
procps/ps.c
41
procps/ps.c
@@ -49,14 +49,12 @@ static const int TERMINAL_WIDTH = 79; /* not 80 in case terminal has linefo
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct proc_s {
|
typedef struct proc_s {
|
||||||
char
|
char cmd[16]; /* basename of executable file in call to exec(2) */
|
||||||
cmd[16]; /* basename of executable file in call to exec(2) */
|
int ruid; /* real only (sorry) */
|
||||||
int
|
int pid; /* process id */
|
||||||
ruid, /* real only (sorry) */
|
int ppid; /* pid of parent process */
|
||||||
pid, /* process id */
|
char state; /* single-char code for process state (S=sleeping) */
|
||||||
ppid; /* pid of parent process */
|
unsigned int vmsize; /* size of process as far as the vm is concerned */
|
||||||
char
|
|
||||||
state; /* single-char code for process state (S=sleeping) */
|
|
||||||
} proc_t;
|
} proc_t;
|
||||||
|
|
||||||
|
|
||||||
@@ -87,6 +85,8 @@ static void parse_proc_status(char *S, proc_t * P)
|
|||||||
tmp = strstr(S, "State");
|
tmp = strstr(S, "State");
|
||||||
sscanf(tmp, "State:\t%c", &P->state);
|
sscanf(tmp, "State:\t%c", &P->state);
|
||||||
|
|
||||||
|
P->pid = 0;
|
||||||
|
P->ppid = 0;
|
||||||
tmp = strstr(S, "Pid:");
|
tmp = strstr(S, "Pid:");
|
||||||
if (tmp)
|
if (tmp)
|
||||||
sscanf(tmp, "Pid:\t%d\n" "PPid:\t%d\n", &P->pid, &P->ppid);
|
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)
|
|||||||
error_msg("Internal error!");
|
error_msg("Internal error!");
|
||||||
|
|
||||||
/* For busybox, ignoring effective, saved, etc. */
|
/* For busybox, ignoring effective, saved, etc. */
|
||||||
|
P->ruid = 0;
|
||||||
tmp = strstr(S, "Uid:");
|
tmp = strstr(S, "Uid:");
|
||||||
if (tmp)
|
if (tmp)
|
||||||
sscanf(tmp, "Uid:\t%d", &P->ruid);
|
sscanf(tmp, "Uid:\t%d", &P->ruid);
|
||||||
else
|
else
|
||||||
error_msg("Internal error!");
|
error_msg("Internal error!");
|
||||||
|
|
||||||
|
P->vmsize = 0;
|
||||||
|
tmp = strstr(S, "VmSize:");
|
||||||
|
if (tmp)
|
||||||
|
sscanf(tmp, "VmSize:\t%d", &P->vmsize);
|
||||||
|
#if 0
|
||||||
|
else
|
||||||
|
error_msg("Internal error!");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int ps_main(int argc, char **argv)
|
extern int ps_main(int argc, char **argv)
|
||||||
@@ -131,7 +139,7 @@ extern int ps_main(int argc, char **argv)
|
|||||||
terminal_width = win.ws_col - 1;
|
terminal_width = win.ws_col - 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printf(" PID Uid Stat Command\n");
|
printf(" PID Uid VmSize Stat Command\n");
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
if (!isdigit(*entry->d_name))
|
if (!isdigit(*entry->d_name))
|
||||||
continue;
|
continue;
|
||||||
@@ -150,7 +158,10 @@ extern int ps_main(int argc, char **argv)
|
|||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
continue;
|
continue;
|
||||||
i = 0;
|
i = 0;
|
||||||
len = printf("%5d %-8s %c ", p.pid, uidName, p.state);
|
if(p.vmsize == 0)
|
||||||
|
len = printf("%5d %-8s %c ", p.pid, uidName, p.state);
|
||||||
|
else
|
||||||
|
len = printf("%5d %-8s %6d %c ", p.pid, uidName, p.vmsize, p.state);
|
||||||
while (((c = getc(file)) != EOF) && (i < (terminal_width-len))) {
|
while (((c = getc(file)) != EOF) && (i < (terminal_width-len))) {
|
||||||
i++;
|
i++;
|
||||||
if (c == '\0')
|
if (c == '\0')
|
||||||
@@ -235,8 +246,10 @@ extern int ps_main(int argc, char **argv)
|
|||||||
if (*uidName == '\0')
|
if (*uidName == '\0')
|
||||||
sprintf(uidName, "%ld", info.euid);
|
sprintf(uidName, "%ld", info.euid);
|
||||||
|
|
||||||
len = printf("%5d %-8s %c ", info.pid, uidName, info.state);
|
if(p.vmsize == 0)
|
||||||
|
len = printf("%5d %-8s %c ", p.pid, uidName, p.state);
|
||||||
|
else
|
||||||
|
len = printf("%5d %-8s %6d %c ", p.pid, uidName, p.vmsize, p.state);
|
||||||
if (strlen(info.command_line) > 1) {
|
if (strlen(info.command_line) > 1) {
|
||||||
for( j=0; j<(sizeof(info.command_line)-1) && j < (terminal_width-len); j++) {
|
for( j=0; j<(sizeof(info.command_line)-1) && j < (terminal_width-len); j++) {
|
||||||
if (*(info.command_line+j) == '\0' && *(info.command_line+j+1) != '\0') {
|
if (*(info.command_line+j) == '\0' && *(info.command_line+j+1) != '\0') {
|
||||||
|
Reference in New Issue
Block a user