Subject: ps -o field=HEADING,field2=HEADING2
To: None <tech-userlevel@netbsd.org>
From: Alan Barrett <apb@cequrux.com>
List: tech-userlevel
Date: 09/11/2006 00:30:53
Several issues with ps:

1) SUSv2 says that {ps -o "field1=HEADING1,field2=HEADING2"} specifies
only one field: field1, whose heading is "HEADING1,field2=HEADING2".
NetBSD's ps thinks that it specifies two fields: field1 with heading
"HEADING1", and field2 with heading "HEADING2".  I think we should
change to be SUS compatible here.  Any objections?

2) SUSv2 says that, if all the fields have null headings, then no
heading is printed at all.  For example, {ps -p ${pid} -o "command="}
should print just one line with the command associated with the
specified process.  NetBSD's ps prints a header line containing zero or
more spaces in this case.  I think we should be SUS compatible here, and
I have already fixed this in my working tree.  Any objections?

3) Multiple -O options don't work as expected.  {ps -O %mem -O %cpu}
puts the %mem column in the right place (just after the pid column), but
puts the %cpu column at the end.  In contrast, {ps -O %mem,%cpu} works
as I expected.  Any objections to changing this?

4) If you try to print a column multiple times with different headings,
the last heading is used for all copies.  For example, try {ps -o
pid=AAA -o pid=BBB}.

5) The Coverity "fix" in revision 1.46 of keyword.c is wrong.  The
allocated memory can't be freed, because the field list might contain
pointers into it.  (For example, try {ps -o ppid= -p $$} to see the
result of keeping a pointer to freed memory.)  I just reverted that
change in my working tree, but perhaps somebody has a better fix.
Note that fixing issue 4 above will also affect this.

6) When I commit whatever fixes I make, I will include regression tests.

--apb (Alan Barrett)