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

时间:2021-12-12 20:56:39

I have to create a Process family as shown in picture, which I did. The next step is to print for all Parent Processes, that they are waiting for their X Childs.

我必须创建一个Process系列,如图所示,我做了。下一步是打印所有父进程,他们正在等待他们的X Childs。

My problem now is how do i figure out or get the information of how many children a parent process has.

我现在的问题是如何弄清楚或获取父进程有多少孩子的信息。

We are programming with language C on the Debian Shell, if you could consider this, while giving your answer that would be nice.

我们正在使用Debian Shell上的语言C编程,如果你能考虑到这一点,同时给出你的答案会很好。

I didn't write my code down here on purpose, because I don't want to get code-based answers but ideas and tipps with arguments like a while for a loop... I hope you understand what I mean ^^

我没有故意在这里写下我的代码,因为我不想得到基于代码的答案,但是想法和tipps用一些循环的参数......我希望你理解我的意思^^

Thanks in advance.

提前致谢。

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

1 个解决方案

#1


2  

Following would be very basic steps you would like to do:

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

PS: Assuming you have not completed recursive function calls yet.

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

#1


2  

Following would be very basic steps you would like to do:

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

PS: Assuming you have not completed recursive function calls yet.

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