【发布时间】:2012-10-10 03:08:19
【问题描述】:
可能重复:
Working of fork() in linux gcc
Why does this code print two times?
#include<stdio.h>
main()
{
printf("hello\n");
fork();
}
上面的代码打印了一次“hello”。下面的代码打印了两次“hello”。
#include<stdio.h>
main()
{
printf("hello");
fork();
}
上面的代码打印了两次“hello”。
请有人解释一下这种奇怪的行为。
【问题讨论】:
-
这已经被问过多次了。请使用搜索功能..
-
如果你使用 "\nhello\n" 会发生什么?
-
输出缓冲区被复制到孩子,没有换行符不为空。
标签: c operating-system fork