Language: C, OS: Linux
the code:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main(void)
{
fork();
printf("hello world\n");
fork();
printf("bye\n");
return 0;
}
Conclusion:
hello world
bye
hello world
bye
hello world
bye
hello world
bye
In accordance with this , and this , printf() buffers output until a newline is encountered.
So, why do we have 4 "peace hello" in this case? (instead of 2 "hello world")
Edit : Sorry, but, like @GregHewgill, I run this program from an environment where the output cannot be directly connected to the terminal, when I check it again on my computer, it just starts as expected.
source
share