I just made a simple demo program in C
to see how fork()
works and came across something that I don't understand. In this example:
void fork2()
{
printf("A");
fork();
printf("B");
}
The output is ABAB
, but in this example:
void fork2()
{
printf("A\n");
fork();
printf("B\n");
}
The output is ABB
(separate lines of course). The second one makes sense, because if I understand fork()
correctly it spawns a new child that starts right after where the fork()
took place (so printf("B\n");
in this case). What I don't understand, is why the output is different when I include the new line character.