• <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);"

            中文字幕无码精品亚洲资源网久久| 欧美久久天天综合香蕉伊| 无码人妻久久一区二区三区| 麻豆亚洲AV永久无码精品久久| 久久精品夜夜夜夜夜久久| 91久久精品无码一区二区毛片| 精品久久久无码中文字幕| 国产aⅴ激情无码久久| 国产精品久久久亚洲| 思思久久99热免费精品6| 亚洲AV无码久久精品蜜桃| 久久AAAA片一区二区| 久久99热国产这有精品| 亚洲国产欧洲综合997久久| 色偷偷偷久久伊人大杳蕉| 97久久天天综合色天天综合色hd| 国产精品免费久久久久影院| 伊人久久大香线蕉av一区| 久久这里只有精品久久| 久久久久久久久久久精品尤物 | 99久久无色码中文字幕| 欧美精品福利视频一区二区三区久久久精品 | 久久亚洲国产中v天仙www| 久久精品国产亚洲AV蜜臀色欲| 91精品国产91久久久久久蜜臀| 日本欧美久久久久免费播放网| 伊色综合久久之综合久久| 久久AⅤ人妻少妇嫩草影院| 国产精品久久久久久久久久免费| 久久午夜伦鲁片免费无码| 囯产精品久久久久久久久蜜桃| 一97日本道伊人久久综合影院| 久久亚洲欧洲国产综合| 国产精品激情综合久久| 久久国产免费| 亚洲欧美国产日韩综合久久| 免费精品久久久久久中文字幕| 久久精品国产亚洲Aⅴ香蕉| 国产精品99久久精品爆乳| 久久久久无码精品| 日韩影院久久|