• <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 閱讀(906) 評論(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);"

            国产精品岛国久久久久| 久久精品国产72国产精福利| 久久天天躁狠狠躁夜夜不卡| 中文精品99久久国产| 亚洲国产精品久久久天堂| 久久久亚洲欧洲日产国码aⅴ| 久久精品人人做人人爽97| 国产成人无码精品久久久久免费| 久久综合色之久久综合| 久久精品一本到99热免费| 欧美亚洲另类久久综合婷婷| 区久久AAA片69亚洲| 久久青青草原精品影院| 久久精品一区二区三区中文字幕| 久久伊人五月丁香狠狠色| 久久婷婷久久一区二区三区| 亚洲伊人久久成综合人影院| 2021久久精品国产99国产精品| 久久久久亚洲AV成人网| 激情伊人五月天久久综合| 亚洲人成无码久久电影网站| 97久久精品无码一区二区天美| 午夜精品久久久久久| 999久久久免费国产精品播放| 久久人人爽人人爽人人av东京热| 久久久国产乱子伦精品作者| 久久综合给合综合久久| 久久99精品久久久大学生| 99久久精品毛片免费播放| 精品久久久久久中文字幕大豆网| 久久精品国产99国产精品亚洲| 久久er热视频在这里精品| 伊人久久大香线蕉成人| 久久综合视频网站| 久久久91人妻无码精品蜜桃HD| 久久免费精品一区二区| 久久精品国产亚洲AV麻豆网站| 五月丁香综合激情六月久久| 久久经典免费视频| 99久久无色码中文字幕人妻| 久久久久亚洲精品日久生情 |