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

Cyrille Lefevre cyrille.lefevre at laposte.net
Fri Mar 26 14:15:03 PST 2004


"Garance A Drosihn" <drosih at rpi.edu> wrote:

> [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].

argh! thread not seen before. please, see my post in -arch entiled :
posix ps (was Re: Adding `pgrep' and `pkill' to /usr/bin)

> 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).

done also

>      Adds the -A option of SUSv3 (exactly the same as `-ax')

well, if sunos -g option is added (done in my implementation),
-A (posix) is more -agx than -ax, while -d (posix) stands for -ag.

>      Adds the `-G gidlist' and '-g pgidlist' options of SYSv3.
>           (note that this replaced a null `-g' option...)

also done.

>      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.

please, don't. for two reason :
- don't try to mix bsd/posix options. this will be more confusing
  to have yet another non conformant option.
- prefer a switch and/or environment variable to switch between
  bsd and posix syntax. and stay conformant to each syntax
  depending to which syntax was selected. a kind of what
  is done on tru64 (w/ or w/o dash), irix (_XPG=1 env),
  hpux (UNIX95=1 env), linux (PS_PERSONALITY=posix env),
  etc.

>      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...

also done.

>      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.

also done

>      Better parsing of options.  Better error messages for
>           invalid values (IMO).

also done.

>      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."

not seen, so, not done for instance but will be.

>      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.

not done but cleaner.

> 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"!

my first implementation statically add all susv3 plus some solaris options,
many keywords or aliases. the current implementation I'm working on may
dynamically switch between one or another syntax (principally bsd, posix,
hpux, irix, sunos, solaris (posix and ucb) and tru64(posix and bsd)) and
may also combine some of them.

I could provide you the patch for the statically (#ifdef's) posix adds or,
if you prefer to wait a week or two, a patch for the dynamically posix
adds I'm working on.

Cyrille Lefevre.
-- 
home: mailto:cyrille.lefevre at laposte.net


More information about the freebsd-standards mailing list