如何查找父进程的所有子进程(在 C 中)

How to find all child process of a parent process (in C)

我必须创建一个进程系列,如图所示,我已经这样做了。 下一步是为所有父进程打印,它们正在等待它们的 X 子进程。

我现在的问题是如何计算或获取父进程有多少子进程的信息。

我们正在 Debian Shell 上使用 C 语言编程,如果您能考虑一下,同时给出您的答案,那就太好了。

我不是故意把我的代码写在这里的,因为我不想得到基于代码的答案,而是想法和带有参数的提示,比如循环……我希望你能理解我的意思意思是^^

提前致谢。

以下是您想要执行的非常基本的步骤:

PS:假设你还没有完成递归函数调用。

STEP1: First get the process id PID
STEP2:Find the child process IDs for PID and maintain a list (array) of them.
STEP3:Repeat STEP2 for all child process IDs saved in the list