PATCH for a more-POSIX `ps', and related adventures

Garance A Drosihn drosih at rpi.edu
Sat Mar 20 13:17:12 PST 2004


[this is BCC'ed to -arch so more people have a chance to see it, but
  I expect most of the discussion to happen in freebsd-standards].

It started out that I just wanted to get rid of one message that
`ps' writes to stderr in -current but not in -stable.  "As long as
I was there", I thought I'd add support for a comma-separated list
of processes for `ps -p' (as described in SUSv3).  Alexey Dokuchaev
asked if this change got us much closer to POSIX/SUS.  Now it did
get us a *little* closer, but in re-reading SUSv3 I realized that
I didn't get it (that one option) quite as close as I would like.
So, "as long as I was there", I figured I should try to come a
little closer.

Now, after about 30 consecutive "as long as I was there" small
projects, I have an update which:
     Changes -p so it accepts a list of process IDs, and -t so
          it accepts a list of terminal names (instead of only
          allowing a single value).
     Adds the -A option of SUSv3 (exactly the same as `-ax')
     Adds the `-G gidlist' and '-g pgidlist' options of SYSv3.
          (note that this replaced a null `-g' option...)
     Adds a `-R ruserlist' option, which is the same as what
          SYSv3 describes for `-u' (we already have a `-u').
          Amazingly, none of solaris, linux, or irix seem to
          have any kind of `-R' option.
     Adds a `-s sidlist' option, which is not in SUSv3, but
          it is in solaris, linux, and irix -- and it's an
          option I have personally wished for on occasion...
     Allows the user to specify any of these "selector options"
          multiple times, and have it keep adding to that
          list instead of replacing values for that list.
     Better parsing of options.  Better error messages for
          invalid values (IMO).
     Fixes interactions between all these "selector options",
          & our `-x' option (which is not mentioned in SUSv3).
          For the selector options, I tried to meet the
          description of: "If any are specified, the default
          list shall be ignored and ps shall select the
          processes represented by the inclusive OR of all
          the selection-criteria options."
     Applies all these selection criteria *before* sorting
          the list of processes we get from kvm_getprocs(),
          and before using the list to compute the sizes of
          the output fields.

That does not get us matching POSIX/SUSv3, but it does get us a
lot closer.  There are a few questions/issues that came up for me
while writing this, but I'll list those in separate messages.  I'll
also do a minimal update to the man page before commiting this.

I wanted to do this without bloating up the size of `ps' by too
much, and on i386 the executable has grown by --- 164 bytes!
(0.6% increase)!    [at this point I will do a touchdown-style
victory dance, and spike my keyboard into the floor...]

The update weighs in at almost 900 lines, and is available at:
http://people.freebsd.org/~gad/ps-susv3.diff

I certainly didn't intend to end up with that large of an update,
but at this point I'm not going to go back and try to break it
down into 30 separate updates of 50 lines each...

Please look it over, try it out, and let me know if these options
seem to work the way you'd expect them to, or if I have messed
anything up.  And please please PLEASE -- don't give me any more
ideas of something *else* I could do "as long as I'm there"!

-- 
Garance Alistair Drosehn            =   gad at gilead.netel.rpi.edu
Senior Systems Programmer           or  gad at freebsd.org
Rensselaer Polytechnic Institute    or  drosih at rpi.edu


More information about the freebsd-standards mailing list