Bug 454370

Summary: headers format parsing wrong (e.g. ps -o pid=,cmd=)
Product: Red Hat Enterprise Linux 4 Reporter: Mikel Ward <mikel>
Component: procpsAssignee: Daniel Novotny <dnovotny>
Status: CLOSED WONTFIX QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: low    
Version: 4.6CC: albert
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2008-07-21 07:14:55 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Mikel Ward 2008-07-08 01:42:18 UTC
POSIX says you can disable the ps header by making all field headers null
http://www.opengroup.org/onlinepubs/009695399/utilities/ps.html

The -o option allows the output format to be specified under user control.

The application shall ensure that the format specification is a list of names
presented as a single argument, <blank> or comma-separated. Each variable has a
default header. The default header can be overridden by appending an equals sign
and the new text of the header. The rest of the characters in the argument shall
be used as the header text. The fields specified shall be written in the order
specified on the command line, and should be arranged in columns in the output.
The field widths shall be selected by the system to be at least as wide as the
header text (default or overridden value). If the header text is null, such as
-o user=, the field width shall be at least as wide as the default header text.
If all header text fields are null, no header line shall be written.

This doesn't seem to be working on RHEL4.  Instead, it appears to be setting the
header for the first column to the specifier for the second column.

# ps -o pid=,cmd=
,cmd=
31721
32307
32581

It should give output equivalent to ps -o pid,cmd but without the header line,
e.g. if ps -o pid,cmd gives this:

  PID CMD
31721 /bin/bash
32307 vi inst
32617 ps -o pid,cmd

Then ps -o pid=,cmd= should give this:

31721 /bin/bash
32307 vi inst
32617 ps -o pid,cmd

procps-3.2.3-8.9

The problem also appears to happen on my Fedora 9 laptop, which has
procps-3.2.7-20.fc9.i386.

Comment 1 Mikel Ward 2008-07-15 07:46:27 UTC
Ew.  They changed the behavior in the latest POSIX standard.

When they say "argument", they now mean everything in the argument to -o:

  APPLICATION USAGE

  There is no special quoting mechanism for header text. The header text is
  the rest of the argument. If multiple header changes are needed, multiple -o
  options can be used, such as:

  ps -o "user=User Name" -o pid=Process\ ID



Comment 2 Tomas Smetana 2008-07-21 07:14:55 UTC
This must be changed in the upstream version first and definitely won't get
there from RHEL.  No API changes should appear in stable releases.  

Comment 3 Albert Cahalan 2009-05-10 06:29:15 UTC
$ ps -o pid=,cmd=
,cmd=
 6496
 6532
$ PS_PERSONALITY=linux ps -o pid=,cmd=
6496 bash
6533 ps -o pid=,cmd=
$ PS_PERSONALITY=posix ps -o pid=,cmd=
,cmd=
 6496
 6534

The default personality is POSIX (insane) unless you use
a non-POSIX option.

I encourage you to point out to the POSIX committee that
nobody likes the insane POSIX parsing. They have a mailing
list, austin-group-l if I remember right,
where you can send edits to the standard. The comma should
just be unavailable; quoting is certainly not required.
(if they insist, use ",," to put a common in a header)
Probably you'll get better luck making "," after "=" have
undefined behavior, but a few years later somebody may
see that as an omission and restore the insanity.