#include "csapp.h"
int main()
{
int i;
for (i = 0; i < 2; i++)
fork();
printf("hello\n");
exit(0);
}
Run Code Online (Sandbox Code Playgroud)
/*
* .------------------------
* |
* |
* |
* .-----------.------------------------
* |
* |
* | .------------------------
* | |
* | |
* | |
* .-----------.------------------------
* fork fork
* i=0 i=1
*/
Run Code Online (Sandbox Code Playgroud)
在过程照片中,似乎代码将打印“ hello”四次。为什么在我的centos中打印“ hello”三遍?