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

标签 c linux shell process parallel-processing

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

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

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

我不是故意把我的代码写在这里的,因为我不想得到基于代码的答案,而是想法和带有参数的提示,比如 while for a loop...我希望你明白我的意思 ^ ^

提前致谢。

How the process family looks alike. Picture!

最佳答案

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

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

关于c - 如何查找父进程的所有子进程(在 C 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33456328/

相关文章:

c++ - GCC 4.4 fails to link valid C++11 code, when options are -std=C++0x -O0

linux - Python 不接受 crontab

python - 命令在 shell 中有效,但在子进程中无效

linux - 在一行中使用 awk 和 stat 来打印 stat 的值

linux - FIFO 到 grep 到文件

c - *可能* unsigned char 等于 EOF?

c - NSight VS Edition - 它包含在 CUDA 5.0 工具包中吗?如何使用它?

bash - 如何查看哪些用户正在执行命令(Shell 脚本)

C 编程错误 - 计数器已定义?

c - 如何在 mingw-w64 gcc 7.1 中打印 size_t 而不发出警告?