Search code examples
clinuxprocesspid

Is there any way in C to know how many processes there are with the same pgid?


I want to know if there is any function in C (Linux) to know how many processes are there with a certain pgid. For example:

  PID  PGID  PPID COMMAND
 9024 27852 27855 ./asdf
 9033 27852 27856 ./asdf
 9035 27852 27854 ./asdf
 9037 27852 27856 ./asdf
 9039 27852 27854 ./asdf

If I have these processes, the function(27852) will return 5 processes.


Solution

  • Succinctly, No — AFAICT.

    POSIX provides a number of functions for manipulating process groups, but not an interrogation function to find out which processes belong to a specified process group. This is consistent with other system calls; there are no system calls that return fully open-ended lists of 'items of interest'.

    You can search through the Linux manual pages at http://man7.org/linux/man-pages:

    The same names as in POSIX turn up; no other relevant looking entries turn up.