another of the fields available in toolbox ps, that someone
coincidentally asked me how to get just last week.

-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.
From 844cfb802ee7185d6314e59744efa839b96f9281 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Wed, 18 Nov 2015 21:33:02 -0800
Subject: [PATCH] Add ps "psr" field.

We probably don't want Android's ps -c, but we should support -o psr.
---
 toys/posix/ps.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index e42e7ec..15e4069 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -92,6 +92,7 @@ config PS
       PID     Process ID
       PPID    Parent Process ID
       PRI     Priority
+      PSR     Processor last executed on
       RGID    Real (before sgid) group ID
       RGROUP  Real (before sgid) group name
       RSS     Resident Set Size (memory currently used)
@@ -242,12 +243,12 @@ static int do_ps(struct dirtree *new)
     // Default: unsupported (5 "C")
     sprintf(out, "-");
 
-    // PID, PPID, PRI, NI, ADDR, SZ, RSS, PGID, VSS, MAJFL, MINFL
-    if (-1!=(i = stridx((char[]){3,4,6,7,8,9,24,19,23,25,30,0}, field->which)))
+    // PID, PPID, PRI, NI, ADDR, SZ, RSS, PGID, VSS, MAJFL, MINFL, PSR.
+    if (-1!=(i = stridx((char[]){3,4,6,7,8,9,24,19,23,25,30,33,0}, field->which)))
     {
       char *fmt = "%lld";
 
-      ll = slot[((char[]){0,1,15,16,27,20,21,2,20,9,7})[i]];
+      ll = slot[((char[]){0,1,15,16,27,20,21,2,20,9,7,36})[i]];
       if (i==2) ll--;
       if (i==4) fmt = "%llx";
       else if (i==5) ll >>= 12;
@@ -451,13 +452,13 @@ static char *parse_o(char *type, int length)
          "F", "S", "UID", "PID", "PPID", "C", "PRI", "NI", "ADDR", "SZ",
          "WCHAN", "STIME", "TTY", "TIME", "CMD", "COMMAND", "ELAPSED", "GROUP",
          "%CPU", "PGID", "RGROUP", "RUSER", "USER", "VSZ", "RSS", "MAJFL",
-         "GID", "STAT", "RUID", "RGID", "MINFL", "LABEL", "CMDLINE"
+         "GID", "STAT", "RUID", "RGID", "MINFL", "LABEL", "CMDLINE", "PSR"
   };
   // TODO: Android uses -30 for LABEL, but ideally it would auto-size.
   signed char widths[] = {1,-1,5,5,5,2,3,3,4+sizeof(long),5,
                           -6,5,-8,8,-27,-27,11,-8,
                           4,5,-8,-8,-8,6,5,6,
-                          8,-5,4,4,6,-30,-27};
+                          8,-5,4,4,6,-30,-27,3};
   int i, j, k;
 
   // Get title, length of title, type, end of type, and display width
-- 
2.6.0.rc2.230.g3dd15c0

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to