How to get PPID with PS using BSD options

user53029 asked:

I’m looking for a ps string that will give me all the output headers of
“ps aux” but with the PPID. So far, I can only get the PPID column using ps -ef. I have tried numerous combinations but have not been able to find one that accomplishes my goal. Can this be done?


I answered:

Now that we know what you really want…

Use -o to select your desired fields. For instance:

$ ps -eo pid,ppid,%cpu,%mem,args
  PID  PPID %CPU %MEM COMMAND
    1     0  0.0  0.0 /usr/lib/systemd/systemd --system --deserialize 22
...more procs...
 1522  3205  0.0  0.0 nginx: worker process
 1523  3205  0.0  0.0 nginx: worker process
 1525  3205  0.0  0.0 nginx: worker process
 1527  3205  0.0  0.0 nginx: worker process
 1528  3205  0.0  0.0 nginx: worker process
 1529  3205  0.0  0.0 nginx: worker process
 3205     1  0.0  0.0 nginx: master process /usr/sbin/nginx
...more procs...

A complete list of the fields you can use is in the man page.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.