如何在C项目中获得状态流程?

问题描述

对于我的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

我也相信您的问题已得到here

的回答

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...