diff options
Diffstat (limited to 'toolbox')
-rw-r--r-- | toolbox/ps.c | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/toolbox/ps.c b/toolbox/ps.c index de141fc..c68438b 100644 --- a/toolbox/ps.c +++ b/toolbox/ps.c @@ -29,9 +29,12 @@ static char *nexttok(char **strp) #define SHOW_CPU 8 #define SHOW_MACLABEL 16 #define SHOW_NUMERIC_UID 32 +#define SHOW_ABI 64 static int display_flags = 0; +static void print_exe_abi(int pid); + static int ps_line(int pid, int tid, char *namefilter) { char statline[1024]; @@ -171,7 +174,11 @@ static int ps_line(int pid, int tid, char *namefilter) else printf(" %.2s ", get_sched_policy_name(p)); } - printf(" %08x %08x %s %s", wchan, eip, state, cmdline[0] ? cmdline : name); + printf(" %08x %08x %s ", wchan, eip, state); + if (display_flags & SHOW_ABI) { + print_exe_abi(pid); + } + printf("%s", cmdline[0] ? cmdline : name); if(display_flags&SHOW_TIME) printf(" (u:%d, s:%d)", utime, stime); @@ -180,6 +187,39 @@ static int ps_line(int pid, int tid, char *namefilter) return 0; } +static void print_exe_abi(int pid) +{ + int fd, r; + char exeline[1024]; + + sprintf(exeline, "/proc/%d/exe", pid); + fd = open(exeline, O_RDONLY); + if(fd == 0) { + printf(" "); + return; + } + r = read(fd, exeline, 5 /* 4 byte ELFMAG + 1 byte EI_CLASS */); + close(fd); + if(r < 0) { + printf(" "); + return; + } + if (memcmp("\177ELF", exeline, 4) != 0) { + printf("?? "); + return; + } + switch (exeline[4]) { + case 1: + printf("32 "); + return; + case 2: + printf("64 "); + return; + default: + printf("?? "); + return; + } +} void ps_threads(int pid, char *namefilter) { @@ -227,7 +267,9 @@ int ps_main(int argc, char **argv) display_flags |= SHOW_PRIO; } else if(!strcmp(argv[1],"-c")) { display_flags |= SHOW_CPU; - } else if(isdigit(argv[1][0])){ + } else if(!strcmp(argv[1],"--abi")) { + display_flags |= SHOW_ABI; + } else if(isdigit(argv[1][0])){ pidfilter = atoi(argv[1]); } else { namefilter = argv[1]; @@ -239,10 +281,11 @@ int ps_main(int argc, char **argv) if (display_flags & SHOW_MACLABEL) { printf("LABEL USER PID PPID NAME\n"); } else { - printf("USER PID PPID VSIZE RSS %s%s %s WCHAN PC NAME\n", + printf("USER PID PPID VSIZE RSS %s%s %s WCHAN PC %sNAME\n", (display_flags&SHOW_CPU)?"CPU ":"", (display_flags&SHOW_PRIO)?"PRIO NICE RTPRI SCHED ":"", - (display_flags&SHOW_POLICY)?"PCY " : ""); + (display_flags&SHOW_POLICY)?"PCY " : "", + (display_flags&SHOW_ABI)?"ABI " : ""); } while((de = readdir(d)) != 0){ if(isdigit(de->d_name[0])){ |