-2

Child 进程如何使用 Fork() 函数生成。

例如:一个进程执行代码 fork() fork() fork()

创建的“子”进程总数是/是?

4

1 回答 1

1

假设您在 Main 中执行了如下所示的总数 fork,那么将创建总共 2power(3) = 8 个进程,因此,8-1 =7 个子进程

要查看进程,请在 linux 上使用 ps

例如:

#include <unistd.h>    
#include <sys/types.h>  
#include <errno.h>      
#include <stdio.h>      
#include <sys/wait.h>   
#include <stdlib.h>     

int main()
{
/*-------------your code part------------*/
    fork();
    fork();
    fork();
/*-------------your code part------------*/
}
于 2012-05-12T20:32:10.493 回答