Search code examples
shellunixposixportabilityps

How portable is the `ps` command?


I'm making a bash script and I'd like to make sure it's portable. For context, the command will be the part of tmux-resurrect plugin.

I want to use this command: ps -eo ppid,command. Is that command portable?

I'd also be glad to hear how to check that myself. For example: maybe there's a service that can test commands on the large number of operating systems etc?


Solution

  • The POSIX Standard is publicly available on the web. Yes, ps is one of the standardized utilities. If you stick to the standard options, you should be pretty portable.

    Note however, that forcing some utilities to behave posixly correct, setting certain environment variables might be necessary. In particular, systems using the GNU utilities may need POSIXLY_CORRECT=yes or similar being set.