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.
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'.
getpgid()
setpgid()
getpgrp()
setpgrp()
killpg()
posix_spawnattr_getpgroup()
posix_spawnattr_setpgroup()
tcgetpgrp()
tcsetpgrp()
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.