[Toybox] Moving ps name fields around.

enh enh at google.com
Mon Jun 13 17:29:41 PDT 2016


AOSP is now using this, and ps lgtm.

i also think NAME and CMD now gives me what i need for top, so i'll
take another look at getting that switched over this week.

(why did it take me 3 days to run 'ps'? my laptop died last week, and
on Friday i left my development N9 in the bootloader -- where the
screen eats more power than USB can supply, and there's no screensaver
-- so by the time i had a working laptop again on Sunday, the device
on my desk on the other end of the ssh connection was dead.)

On Fri, Jun 10, 2016 at 4:50 PM, Rob Landley <rob at landley.net> wrote:
> Right, I think I figured it out: TNAME->NAME->COMM->CMD.
>
> I want to move TNAME to NAME, and move the old NAME to
> COMM, which means moving what COMM is doing to CMD. (Right
> now CMD is just an alias for two other fields, not a unique
> behavior anyway.)
>
> That means we go from this:
>
>   ARGS    Command line (argv[] -path)   CMD   COMM, or ARGS with -f
>   CMDLINE Command line (argv[])         COMM  Original command name (stat2)
>   COMMAND Command name (/proc/$PID/exe) NAME  Command name (COMMAND -path)
>   TNAME   Thread name  (argv[0] of $PID)
>
> To this:
>
>   ARGS    Command line (argv[] -path)   CMD  Original command name (stat2)
>   CMDLINE Command line (argv[])         COMM Command name (/proc/$PID/exe -path)
>   COMMAND Command path (/proc/$PID/exe) NAME Process name (argv[0] of $PID -path)
>
> The reason for all the shuffling is posix defines 4 of those
> fields badly in a way that violates a design assumption of
> toybox ps: that any header field it displays can be used
> as a ps -o FIELD name to display that field.
>
> Posix also thinks that argv[] (I.E. /proc/$PID/cmdline) is
> the only source of command line information, when we've also
> got /proc/$PID/stat and /proc/$PID/exe. And posix never
> mentions stripping the path from argv[0], without which
> you often display nothing but path with no command name
> before running out of space in the field.
>
> Initially I was thinking of bumping the old NAME to CMD, but
> that made ubuntu's "vi" display different data: the exe is
> "vim.tiny" but the stat[2] name is "vi". Ubuntu's ps shows
> the stat[2] name for cmd (at least without -f), so cmd
> should be stat[2].
>
> While I COULD have toybox lie and do "COMM=CMD" in the default
> string, that bumps up against the above "what we show
> is what you can -o" assumption, in the default output
> (with no arguments), which is just icky.
>
> Moving it around this way, Android has CMD and NAME in the
> default outputs, showing stat[2] and argv[0] of $PID
> respectively.
>
> After this, CMD is the only string field with length -15 and
> that's because stat[2] is trimmed to 15 chars by Linux anyway.
>
> You can see all three with:
>
>   ./ps -Ao pid,tid,tcnt,cmd,comm,name
>
> ARGS shows all the arguments as well as the initial command name.
> CMDLINE is ARGS without stripping the path from argv[0]
> COMMAND is COMM without stripping the path.
>
> I note that in CMDLINE I could quote each argument, and put
> backslashes before quote characters and backslashes. That's
> _the_ simplest escaping mechanism.
>
> Rob
> _______________________________________________
> Toybox mailing list
> Toybox at lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net



-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.



More information about the Toybox mailing list