GNU ps supports BSD-style options, UNIX-style options, and GNU long options. Is using one of these types (in scripts and at the command line) preferred over the others?

I get the impression from the manpage that the functionality of the option styles does not overlap completely.


Generally speaking just use the set of options that gives you the results you want.

For the sake of (other people's) sanity & portability I suggest sticking with BSD-style or SysV-style arguments -- for the most part modern systems accept both of those argument sets, and that way when the script you wrote to solve a problem on Linux gets dropped onto a system that doesn't understand GNU-style long options it still works (all the world is not a Linux machine).


Is using one of these types (in scripts and at the command line) preferred over the others?

This largely depends on the target platforms your scripts should run on. If your scripts should run only on Linux go with the GNU-style options, if they should also be usable on *BSD go with the BSD-style options and last but not least if they should run on a wide range of unixoid systems (e. g. Solaris) go with the UNIX-style options.

  • Seriously? The GNU-style options are the long options. – Jim Hunziker May 11 '10 at 14:23

Whatever POSIX says. I'm not up to stuff on this, but I would guess scripts using ps won't be very portable anyway.

  • +1 for "scripts using ps won't be very portable". – l0b0 Oct 7 '12 at 8:00

I think you will find the POSIX or SVR4 options are far more common.

I generally parse uname output, and select the correct /bin/ps, /usr/bin/ps and arguments based on that value. On unsupported platforms, I just exit, I don't guess. On linux, I set $PS_PERSONALITY to "posix" and unset $I_WANT_A_BROKEN_PS in case a user has that set for some reason. This is just a defensive measure.

The GNU getopt_long() style is useful only on Linux, and even if that's what you're going for, people are far more familiar with the short options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.