In "https://stackoverflow.com/questions/13038143/how-to-get-pids-in-one-process-group-in-linux-os" I see all answers mentioning ps
and none mentioning /proc
.
"ps" seems to be not very portable (Android and Busybox versions expect different arguments), and I want to be able list pids with pgids with simple and portable tools.
In /proc/…/status I see Tgid:
(thread group ID), Gid:
(group id for security, not for grouping processes together), but not PGid:
…
What are other (not using ps
) ways of getting pgid from pid?
Best Answer
You can look at field 5th in output of
/proc/[pid]/stat
.From
man proc
:Note that you cannot use:
Because that file is not a blank separated list. The second field (the process name may contain blanks or even newline characters). For instance, most of the threads of
firefox
typically have space characters in their name.So you need to print the 3rd field after the last occurrence of a
)
character in there.