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
Post a Comment