• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Prayer

            在一般中尋求卓越
            posts - 1256, comments - 190, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            UNIX 標準輸入 全緩存和行緩存 的區別

            Posted on 2009-05-06 10:03 Prayer 閱讀(907) 評論(0)  編輯 收藏 引用 所屬分類: LINUX/UNIX/AIX

            This case may relates to stdio buffering.
            If stdout is a terminal, it is line buffered. The buffer is flushed when a new line is hit.
            Otherwise, stdout is fully buffered. The buffer is flushed if the buffer is full or the program terminates.flush means clear the stdout.
            如果終端是標準輸出,它就是行緩存的,當遇到新行符,則被刷新一次。
            如果標準輸出不是中斷,那它是全緩存的。如果緩沖區滿或者程序被終止,緩沖區被刷新。


            So
            1) we run bpeek directly, the printf() function is line buffered, when "\n" is hit, the buffer is flushed immediately and "<< output from stdout >>" is printed.
            2) we run bpeek|tail, the printf() functions became fully buffered, when "\n" is hit, the buffer is NOT flushed. The buffer resides in the process's memory. When the process execute fork(), the son gets a copy from the father's memory, that means both father and son process have the unflushed buffer. When the son process exits, the message is printed. When the father exits, the message is printed again.

            We can write a simple program to simulate this:
            ----------------------------
            #include <stdio.h>
            #include <sys/types.h>
            #include <unistd.h>
            int main(){
                    pid_t pid;

                    printf("<< %s >>\n", "output of stdout");
                    pid = fork();

                 if(pid < 0){
                      printf("fork error\n");
                      exit(-1);
                 }else if(pid > 0){
                      wait(NULL);
                      return;
                 }
                 exit(0);
            }


            "To avoid this, we my force printf() to line buffered:
            setvbuf(stdout, buf, _IOLBF, BUFSIZ);"

            亚洲精品蜜桃久久久久久| 久久不见久久见免费视频7| 久久婷婷五月综合国产尤物app | 亚洲精品无码专区久久同性男 | 一本色综合久久| 久久亚洲AV成人无码电影| 久久精品中文騷妇女内射| 精品久久久久一区二区三区| 亚洲精品成人网久久久久久| 热re99久久精品国99热| 久久婷婷色综合一区二区| 无码伊人66久久大杳蕉网站谷歌| 青青青伊人色综合久久| 久久无码高潮喷水| 亚洲国产二区三区久久| 亚洲精品蜜桃久久久久久| 无码8090精品久久一区| 久久久精品人妻一区二区三区四 | 久久99精品国产麻豆蜜芽| 无码人妻久久一区二区三区| 国产成人精品久久二区二区| 国产亚洲精久久久久久无码AV| 久久棈精品久久久久久噜噜| 18岁日韩内射颜射午夜久久成人| 久久久亚洲欧洲日产国码是AV| 久久婷婷国产麻豆91天堂| 无码AV波多野结衣久久| 久久成人18免费网站| 久久青青草原国产精品免费| 久久精品国产亚洲av影院| 久久人妻少妇嫩草AV蜜桃| 久久夜色精品国产www| yellow中文字幕久久网| 天天爽天天爽天天片a久久网| 久久99国产精品尤物| 久久综合香蕉国产蜜臀AV| 久久人与动人物a级毛片| 久久久久久精品免费免费自慰| 日本加勒比久久精品| 婷婷久久综合九色综合九七| 中文国产成人精品久久亚洲精品AⅤ无码精品|