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

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

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