summaryrefslogtreecommitdiffstats
path: root/toolbox/ps.c
diff options
context:
space:
mode:
authorDmitry Shmidt <dimitrysh@google.com>2010-08-18 17:26:26 -0700
committerDmitry Shmidt <dimitrysh@google.com>2010-08-18 17:26:26 -0700
commit8b37c91b934bf22d8ae52bebad7f1f22f16d1132 (patch)
tree9c86862f6dca39f6610dfc3cb2a2afae85f4157c /toolbox/ps.c
parent8fa95f966088f13b14895aefea87b6c5f0cc78eb (diff)
downloadsystem_core-8b37c91b934bf22d8ae52bebad7f1f22f16d1132.zip
system_core-8b37c91b934bf22d8ae52bebad7f1f22f16d1132.tar.gz
system_core-8b37c91b934bf22d8ae52bebad7f1f22f16d1132.tar.bz2
ps: Add -c flag to show CPU number last executed on
Change-Id: I9a8faef0824c390ef980ce6c33e9c79102884879 Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
Diffstat (limited to 'toolbox/ps.c')
-rw-r--r--toolbox/ps.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/toolbox/ps.c b/toolbox/ps.c
index bc50cfa..2aa3efb 100644
--- a/toolbox/ps.c
+++ b/toolbox/ps.c
@@ -27,6 +27,7 @@ static char *nexttok(char **strp)
#define SHOW_PRIO 1
#define SHOW_TIME 2
#define SHOW_POLICY 4
+#define SHOW_CPU 8
static int display_flags = 0;
@@ -41,7 +42,7 @@ static int ps_line(int pid, int tid, char *namefilter)
int ppid, tty;
unsigned wchan, rss, vss, eip;
unsigned utime, stime;
- int prio, nice, rtprio, sched;
+ int prio, nice, rtprio, sched, psr;
struct passwd *pw;
sprintf(statline, "/proc/%d", pid);
@@ -122,7 +123,7 @@ static int ps_line(int pid, int tid, char *namefilter)
nexttok(&ptr); // nswap
nexttok(&ptr); // cnswap
nexttok(&ptr); // exit signal
- nexttok(&ptr); // processor
+ psr = atoi(nexttok(&ptr)); // processor
rtprio = atoi(nexttok(&ptr)); // rt_priority
sched = atoi(nexttok(&ptr)); // scheduling policy
@@ -142,7 +143,9 @@ static int ps_line(int pid, int tid, char *namefilter)
if(!namefilter || !strncmp(name, namefilter, strlen(namefilter))) {
printf("%-9s %-5d %-5d %-6d %-5d", user, pid, ppid, vss / 1024, rss * 4);
- if(display_flags&SHOW_PRIO)
+ if (display_flags & SHOW_CPU)
+ printf(" %-2d", psr);
+ if (display_flags & SHOW_PRIO)
printf(" %-5d %-5d %-5d %-5d", prio, nice, rtprio, sched);
if (display_flags & SHOW_POLICY) {
SchedPolicy p;
@@ -207,6 +210,8 @@ int ps_main(int argc, char **argv)
display_flags |= SHOW_POLICY;
} else if(!strcmp(argv[1],"-p")) {
display_flags |= SHOW_PRIO;
+ } else if(!strcmp(argv[1],"-c")) {
+ display_flags |= SHOW_CPU;
} else if(isdigit(argv[1][0])){
pidfilter = atoi(argv[1]);
} else {
@@ -216,7 +221,8 @@ int ps_main(int argc, char **argv)
argv++;
}
- printf("USER PID PPID VSIZE RSS %s %s WCHAN PC NAME\n",
+ printf("USER PID PPID VSIZE RSS %s%s %s WCHAN PC NAME\n",
+ (display_flags&SHOW_CPU)?"CPU ":"",
(display_flags&SHOW_PRIO)?"PRIO NICE RTPRI SCHED ":"",
(display_flags&SHOW_POLICY)?"PCY " : "");
while((de = readdir(d)) != 0){