[英]What happens to active child processes when you fork a parent, do all active processes create another process ? Fork();
Bellow is the code of what is going on, and here is an image of what am i trying to do, any help would be appreciated.贝娄是正在发生的事情的代码,这是我正在尝试做的事情的图像,任何帮助将不胜感激。 Trying to draw the diagram of all the processes Code:
尝试绘制所有流程代码的图表:
for(i=0;i<2;i++){
int pid = fork();
if(pid == 0){
fork();
printf("\tA\n");
}
else{
printf("\tB\n");
}
}//for
printf("\tC\n");
return 0;
} }
Mainly missing from your diagram is in the block Child1 as well as Child1.1 a second run through the for
loop, since these children are still inside the loop and their i
is initially also 0.您的图表中主要缺少的是块Child1以及Child1.1第二次运行
for
循环,因为这些孩子仍在循环内,并且它们的i
最初也是 0。
On the other hand, the C=3 in Parent is wrong because C is only printed once at the end, not in the loop.另一方面, Parent中的C=3是错误的,因为C只在最后打印一次,而不是在循环中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.