对于我的 C 项目,我需要知道各种进程处于哪种状态(运行、等待、终止……)。这些进程是我自己使用许多 fork() 创建的。有谁知道该怎么做?
示例:我有一个 PPID = x 的进程,我执行了 3 个 fork() -> 我得到了三个 PID = x+1、PID = x+2 和 PID = x+3(或多或少)的新进程。我需要知道 PID = x+1、PID = x+2 和 PID = x+3 的进程是否正在运行、等待或终止。
如果您执行 3 fork()
,您将拥有超过 3 个新流程。你有 2^n 个进程。n 是你打电话的次数fork()
例如
#include <stdio.h>
#include <sys/types.h>
int main()
{
fork();
fork();
fork();
printf("hello\n");
return 0;
}
打印这个
hello
hello
hello
hello
hello
hello
hello
hello
我也相信你的问题已经在这里得到了回答