I want a simple command to list all the processes and its information from a given PGID.

  • 2
    "man ps" will do the trick – hennr May 18 '16 at 13:58
  • Did the answer below solve your problem? If not, please clarify what did not work; if so, don't forget to use the checkmark to indicate so. Thank you! – Jeff Schaller May 27 '16 at 15:24

I don't see a way to proactively tell ps to select based on pgrp, so you have to request that column then filter on it; something like:

ps axo pgrp,stat,euid,ruid,tty,tpgid,sess,ppid,pid,pcpu,comm | awk -v pgrp=3668 '$1 == pgrp'

ps -eo pgrp,pid,comm | sed -n -e 1p -e ' /3668/ p'

PGRP=3668; ps -eo pgrp,pid,comm | sed -n -e 1p -e " / $PGRP / p"

On Darwin, ps -g $pgid does work as you ask.

On Linux, it doesn't work and you need to use some other solution, as has been suggested.

As an alternative that works on both, you can use ps --ppid $ppid which lists all child processes of the given parent.

pgrep -ag PGID

If PGID is 0, it means pgrep's own process group, eg.

$ cat | cat | cat | pgrep -ag0
7301 cat
7302 cat
7303 cat

(notice that pgrep never includes itself in the listing, and pkill never kills itself)

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.