I am trying the following C code:
int main()
{
printf("text1
");
fork();
printf("text2
");
return 0;
}
I was expecting to get the output where i get two "text1" and two "text2", like:
text1
text1
text2
text2
But, i am, instead, getting:
text1
text2
text2
only one "text1"???
Ok, if child process executes from the fork(), then why do i get two "text1" for following:
int main()
{
printf("text1");
fork();
printf("text2
");
return 0;
}
the output now is:
text1text2
text1text2
If the child process starts after the fork, output should be:
text1
text2
text2
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…