consider the following c programmain()
{
fork();
fork();
printf("hello!\n");
}
为什么会print出4个'hello!'?
是不是这样
读到第一个fork(),program另外copy多一个fork();printf()
so far, you have 1 parent program and exact same child program with the content---- fork(); printf();
each of them read upto second fork() will produce two children programs again, with the content---printf();
It's like a tree.
1
^
1 1
^ ^
11 11
After I tried this simply program in unix, i get the answer
4
so far, you have 1 parent program and exact same child program with the content---- fork(); printf();
each of them read upto second fork() will produce two children programs again, with the content---printf();
It's like a tree.
1
^
1 1
^ ^
11 11
After I tried this simply program in unix, i get the answer
4