C 中有什么方法可以知道有多少进程具有相同的 pgid?

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

我想知道C中有没有函数(Linux)可以知道某个pgid有多少个进程。 例如:

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

如果我有这些进程,函数 (27852) 将 return 5 个进程。

简而言之,没有 — AFAICT。

POSIX 提供了许多操作进程组的函数,但没有提供查询函数来找出哪些进程属于指定的进程组。这与其他系统调用是一致的;没有 return 完全开放式 'items of interest' 列表的系统调用。

您可以在 http://man7.org/linux/man-pages:

处搜索 Linux 手册页

与POSIX中相同的名字出现;没有其他相关的条目出现。