diff options
Diffstat (limited to 'toolbox/ps.c')
-rw-r--r-- | toolbox/ps.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/toolbox/ps.c b/toolbox/ps.c index 57b4280..5458f6b 100644 --- a/toolbox/ps.c +++ b/toolbox/ps.c @@ -28,7 +28,8 @@ static char *nexttok(char **strp) #define SHOW_POLICY 4 #define SHOW_CPU 8 #define SHOW_MACLABEL 16 -#define SHOW_ABI 32 +#define SHOW_NUMERIC_UID 32 +#define SHOW_ABI 64 static int display_flags = 0; @@ -48,7 +49,7 @@ static int ps_line(int pid, int tid, char *namefilter) unsigned utime, stime; int prio, nice, rtprio, sched, psr; struct passwd *pw; - + sprintf(statline, "/proc/%d", pid); stat(statline, &stats); @@ -70,7 +71,7 @@ static int ps_line(int pid, int tid, char *namefilter) } cmdline[r] = 0; } - + fd = open(statline, O_RDONLY); if(fd == 0) return -1; r = read(fd, statline, 1023); @@ -92,7 +93,6 @@ static int ps_line(int pid, int tid, char *namefilter) nexttok(&ptr); // pgrp nexttok(&ptr); // sid nexttok(&ptr); // tty - nexttok(&ptr); // tpgid nexttok(&ptr); // flags nexttok(&ptr); // minflt @@ -132,21 +132,21 @@ static int ps_line(int pid, int tid, char *namefilter) psr = atoi(nexttok(&ptr)); // processor rtprio = atoi(nexttok(&ptr)); // rt_priority sched = atoi(nexttok(&ptr)); // scheduling policy - + nexttok(&ptr); // tty - + if(tid != 0) { ppid = pid; pid = tid; } pw = getpwuid(stats.st_uid); - if(pw == 0) { + if(pw == 0 || (display_flags & SHOW_NUMERIC_UID)) { sprintf(user,"%d",(int)stats.st_uid); } else { strcpy(user,pw->pw_name); } - + if(!namefilter || !strncmp(name, namefilter, strlen(namefilter))) { if (display_flags & SHOW_MACLABEL) { fd = open(macline, O_RDONLY); @@ -229,7 +229,7 @@ void ps_threads(int pid, char *namefilter) sprintf(tmp,"/proc/%d/task",pid); d = opendir(tmp); if(d == 0) return; - + while((de = readdir(d)) != 0){ if(isdigit(de->d_name[0])){ int tid = atoi(de->d_name); @@ -237,7 +237,7 @@ void ps_threads(int pid, char *namefilter) ps_line(pid, tid, namefilter); } } - closedir(d); + closedir(d); } int ps_main(int argc, char **argv) @@ -247,13 +247,15 @@ int ps_main(int argc, char **argv) char *namefilter = 0; int pidfilter = 0; int threads = 0; - + d = opendir("/proc"); if(d == 0) return -1; while(argc > 1){ if(!strcmp(argv[1],"-t")) { threads = 1; + } else if(!strcmp(argv[1],"-n")) { + display_flags |= SHOW_NUMERIC_UID; } else if(!strcmp(argv[1],"-x")) { display_flags |= SHOW_TIME; } else if(!strcmp(argv[1], "-Z")) { |