#include <stdio.h>
#include <unistd.h>
int main()
{
while(1)
{
fprintf(stdout,"hello-out");
fprintf(stderr,"hello-err");
sleep(1);
}
return 0;
}
的上面的輸出我的機器上是代碼睡在while循環期望輸出
hello-errhello-errhello-errhello-errhello-errhello-errhello-errhello-errhello-errhello-errhello-errhello-errhello-errhello-err
我不得不殺程序停止它。 這是正確和預期的行爲。 或者這是錯誤的。這是一個面試問題,因此我在這裏發佈。
你問的問題。你的問號鍵是否被打破。 –
我在那裏看到一個問題,它沒有問號。但是如果你願意,你也可以識別它。 – Skurmedel
10K用戶可以看到一個相同的問題[這裏](http://stackoverflow.com/questions/6283556/buffering-for-stdout-stderr-streams),它由於某種原因被刪除。一個恥辱,因爲它有很好的答案。 – interjay