3

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

0

3 Answers 3

3

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"
1
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)

0

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

On Linux, it doesn't work and you need to use some other solution. You can use ps --ppid $ppid which lists all child processes of the given parent.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .