Merge "Add -n option to ps to print numeric uid"
This commit is contained in:
commit
4067077a44
23
toolbox/ps.c
23
toolbox/ps.c
|
@ -28,6 +28,7 @@ static char *nexttok(char **strp)
|
|||
#define SHOW_POLICY 4
|
||||
#define SHOW_CPU 8
|
||||
#define SHOW_MACLABEL 16
|
||||
#define SHOW_NUMERIC_UID 32
|
||||
|
||||
static int display_flags = 0;
|
||||
|
||||
|
@ -45,7 +46,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);
|
||||
|
||||
|
@ -67,7 +68,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);
|
||||
|
@ -89,7 +90,7 @@ static int ps_line(int pid, int tid, char *namefilter)
|
|||
nexttok(&ptr); // pgrp
|
||||
nexttok(&ptr); // sid
|
||||
tty = atoi(nexttok(&ptr));
|
||||
|
||||
|
||||
nexttok(&ptr); // tpgid
|
||||
nexttok(&ptr); // flags
|
||||
nexttok(&ptr); // minflt
|
||||
|
@ -129,21 +130,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
|
||||
|
||||
|
||||
tty = atoi(nexttok(&ptr));
|
||||
|
||||
|
||||
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);
|
||||
|
@ -189,7 +190,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);
|
||||
|
@ -197,7 +198,7 @@ void ps_threads(int pid, char *namefilter)
|
|||
ps_line(pid, tid, namefilter);
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
int ps_main(int argc, char **argv)
|
||||
|
@ -207,13 +208,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")) {
|
||||
|
|
Loading…
Reference in New Issue