[Toybox] Moving ps name fields around.
Rob Landley
rob at landley.net
Fri Jun 10 16:50:45 PDT 2016
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
More information about the Toybox
mailing list