代码:
printf("hello\n");
//fflush(stdout);
fork();
输出:
hello
代码:
printf("hello\n");
fflush(stdout);
fork();
输出:
hello
hello
说明:系统函数fork()创建新的进程。
printh后打印内容在缓冲区里,fork后,父子进程的缓冲区里也是相同的,进程退出时,缓冲区输出到屏幕,所以有两份。
而fflush(stdout)当然是清空stdout的缓冲区了