2

Here is what I get when I list all processes with -g option:

ps -g -o pid,pgid,ppid
   PID   PGID   PPID
112140 112140 112139
127467 127467 127466
130547 130547 112140
130551 130547 130547
130557 130557 127467

...

ps -g 130547

displays nothing, while I would expect 130547 and 130551. Same for 'ps -s '. Why? Is there a way to display processes belonging to the same group (tree)?

  • 1
    Maybe pstree -g 130547? – Freddy Sep 18 at 21:46
1

On Linux, ps -g selects processes either by group or by session, but not by process group. It treats the arguments as session IDs if they consist solely of digits and as group names otherwise.

ps -g 130547 lists all the processes in the session whose ID is 130547. Presumably process 130547 is not a session leader and therefore there is no process whose session ID is 130547.

Linux ps doesn't have an option to filter by process group. You can list all the processes, or all the processes in a given session, and filter by the pgid field.

ps -g $(ps -p 130547 -o sid=) -o pid,ppid,pgid
ps -e -o pid,ppid,pgid | awk 'NR == 1 || $3 == 130547'

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.