summaryrefslogtreecommitdiffstats
path: root/toolbox/ps.c
diff options
context:
space:
mode:
Diffstat (limited to 'toolbox/ps.c')
-rw-r--r--toolbox/ps.c51
1 files changed, 38 insertions, 13 deletions
diff --git a/toolbox/ps.c b/toolbox/ps.c
index 5458f6b..cf3f05a 100644
--- a/toolbox/ps.c
+++ b/toolbox/ps.c
@@ -1,15 +1,14 @@
-#include <stdio.h>
-#include <stdlib.h>
#include <ctype.h>
+#include <dirent.h>
#include <fcntl.h>
-
+#include <inttypes.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-
#include <sys/stat.h>
#include <sys/types.h>
-#include <dirent.h>
-
-#include <pwd.h>
+#include <unistd.h>
#include <cutils/sched_policy.h>
@@ -31,7 +30,14 @@ static char *nexttok(char **strp)
#define SHOW_NUMERIC_UID 32
#define SHOW_ABI 64
+#if __LP64__
+#define PC_WIDTH 10 /* Realistically, the top bits will be 0, so don't waste space. */
+#else
+#define PC_WIDTH (2*sizeof(uintptr_t))
+#endif
+
static int display_flags = 0;
+static int ppid_filter = 0;
static void print_exe_abi(int pid);
@@ -45,7 +51,8 @@ static int ps_line(int pid, int tid, char *namefilter)
int fd, r;
char *ptr, *name, *state;
int ppid;
- unsigned wchan, rss, vss, eip;
+ unsigned rss, vss;
+ uintptr_t eip;
unsigned utime, stime;
int prio, nice, rtprio, sched, psr;
struct passwd *pw;
@@ -125,7 +132,7 @@ static int ps_line(int pid, int tid, char *namefilter)
nexttok(&ptr); // blocked
nexttok(&ptr); // sigignore
nexttok(&ptr); // sigcatch
- wchan = strtoul(nexttok(&ptr), 0, 10); // wchan
+ nexttok(&ptr); // wchan
nexttok(&ptr); // nswap
nexttok(&ptr); // cnswap
nexttok(&ptr); // exit signal
@@ -147,7 +154,11 @@ static int ps_line(int pid, int tid, char *namefilter)
strcpy(user,pw->pw_name);
}
- if(!namefilter || !strncmp(name, namefilter, strlen(namefilter))) {
+ if(ppid_filter != 0 && ppid != ppid_filter) {
+ return 0;
+ }
+
+ if(!namefilter || !strncmp(cmdline[0] ? cmdline : name, namefilter, strlen(namefilter))) {
if (display_flags & SHOW_MACLABEL) {
fd = open(macline, O_RDONLY);
strcpy(macline, "-");
@@ -173,7 +184,16 @@ static int ps_line(int pid, int tid, char *namefilter)
else
printf(" %.2s ", get_sched_policy_name(p));
}
- printf(" %08x %08x %s ", wchan, eip, state);
+ char path[PATH_MAX];
+ snprintf(path, sizeof(path), "/proc/%d/wchan", pid);
+ char wchan[10];
+ int fd = open(path, O_RDONLY);
+ ssize_t wchan_len = read(fd, wchan, sizeof(wchan));
+ if (wchan_len == -1) {
+ wchan[wchan_len = 0] = '\0';
+ }
+ close(fd);
+ printf(" %10.*s %0*" PRIxPTR " %s ", (int) wchan_len, wchan, (int) PC_WIDTH, eip, state);
if (display_flags & SHOW_ABI) {
print_exe_abi(pid);
}
@@ -268,6 +288,10 @@ int ps_main(int argc, char **argv)
display_flags |= SHOW_CPU;
} else if(!strcmp(argv[1],"--abi")) {
display_flags |= SHOW_ABI;
+ } else if(!strcmp(argv[1],"--ppid")) {
+ ppid_filter = atoi(argv[2]);
+ argc--;
+ argv++;
} else if(isdigit(argv[1][0])){
pidfilter = atoi(argv[1]);
} else {
@@ -278,12 +302,13 @@ int ps_main(int argc, char **argv)
}
if (display_flags & SHOW_MACLABEL) {
- printf("LABEL USER PID PPID NAME\n");
+ printf("LABEL USER PID PPID NAME\n");
} else {
- printf("USER PID PPID VSIZE RSS %s%s %s WCHAN PC %sNAME\n",
+ printf("USER PID PPID VSIZE RSS %s%s %sWCHAN %*s %sNAME\n",
(display_flags&SHOW_CPU)?"CPU ":"",
(display_flags&SHOW_PRIO)?"PRIO NICE RTPRI SCHED ":"",
(display_flags&SHOW_POLICY)?"PCY " : "",
+ (int) PC_WIDTH, "PC",
(display_flags&SHOW_ABI)?"ABI " : "");
}
while((de = readdir(d)) != 0){