1
我不确定在这个程序中要创建多少个进程?我想在while循环中会创建三个子进程。然后,每个子进程将分叉两次,这意味着将有两个子进程加上由该子进程创建的进程也将分叉,并且每个状态将有4个子进程。总共有12个过程。真的吗?这段代码要生成多少个进程?
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
int main(){
pid_t childpid;
int i=0;
while((childpid>0) && (i<3))
{
childpid=fork();
i++;
}
if(childpid==0){
fork();
fork();
}
exit(0);
}
在纸上跟踪它。这是我在Uni学习操作系统设计时做过的事情 – StoryTeller
我想我上周已经看到了这段代码...... –
'pid_t childpid = getpid();'缺少。 – jfs