開始一直輸出hello-std-err,當(dāng)stdout的緩沖區(qū)滿后,一次輸出hello-std-out,接著重復(fù)以上動(dòng)作。 原因是:stdout和stderr是不同的設(shè)備描述符,stdout是塊設(shè)備,而stderr不是。對(duì)于塊設(shè)備,只有遇到下面幾種情況才會(huì)輸出:1)遇到回車,2)緩沖區(qū)滿,3)flush被調(diào)用。而stderr不會(huì),stderr是標(biāo)準(zhǔn)錯(cuò)誤,直接輸出。 下面說以下幾種設(shè)備的緩沖: 標(biāo)準(zhǔn)輸入,輸出是行緩沖,Line buffering is typically used on a stream when it refers to a terminal: standard input and standard output, for example. 舉例來說就是你,printf(stdout, "xxxx"); 而不是printf(stdout, "xxxx\n"),前者會(huì)憋住,直到遇到新行才會(huì)一起輸出 printf(stderr, "xxxxx"),不管有么有\(zhòng)n,都輸出。 |
|