为什么这段代码从分叉执行8次printf?

Rya*_*ing 3 c printf fork

学习决赛,我遇到了这个问题.他们询问以下代码执行printf的次数:

#include    "csapp.h"
void    doit()  {   
Fork();
Fork();
printf("hello\n");
return; 
}
int main()
{
doit();
printf("hello\n");
exit(0);
}
Run Code Online (Sandbox Code Playgroud)

解决方案说它printf执行了8次,但我无法弄清楚原因.我一直试图绘制代码中发生的事情的图片,但我的图片看起来好像只执行了4次.

Ed *_*eal 6

2个叉子 - 四个过程.每个过程有两个printfshello(一个在main与一个在doit-因此8.