"ps -p <pid> -o pid=,..." misbehavior
This bug was originally reported at https://bugs.gentoo.org/555200
Observe the following three variants of the same command. They should have the same output but they don't:
polynomial-c@notebook:~ $ ps p $$ -o pid=,comm=,args= 7899 zsh -zsh polynomial-c@notebook:~ $ ps -p $$ -o pid=,comm=,args= ,comm=,args= 7899 polynomial-c@notebook:~ $ ps --pid $$ -o pid=,comm=,args= 7899 zsh -zsh polynomial-c@notebook:~ $
This bug seems to be available for quite a long time. I could even reproduce it on a SLES11SP3 system with ps from procps-3.2.7
The problem can only be triggered by the following circumstances:
- pid must be submitted using "-p". Neither "p" nor "--pid" can trigger it.
- the output format string must begin with "pid=". Everything else doesn't trigger the bug. So neither "-o comm=,pid=,uid=" nor "-o pid,comm" do trigger it but only "-o pid=,..." notations.
Wow, that is very.. curious. I'll look into ps and see what it thinks it should be doing. I know what is wrong, its in the parsing. It is making the header for pid to be ",comm=,args=" It's now a matter of working out why the parser is doing that.
Would you believe its done that way by design? I think its a stupid design and will be fixing it. Apparently Unix98 specification (or Albert's interpretation) says having a header of foo=bar is fine. To me that's clearly nonsense and leads to user confusion. It took me an hour of so of digging into the bowells of ps source code to see it was "right".
Status changed to closedToggle commit list