c - Why does fork() and printf() output more than I predict? -


this little program:

#include <unistd.h> #include <stdio.h> int main() {   printf("1");   fork();   printf("2");   fork();   return 0; } 

the output of code 12121212 , ask:
why print more 122?

because printf buffered , text printed when program exits. try flush stdout after each print.


Comments

Popular posts from this blog

C# random value from dictionary and tuple -

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -