• <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| 亚洲国产精品一区二区久久hs| 99久久777色| 国产精品无码久久综合| 久久人人爽人人爽人人爽| av无码久久久久不卡免费网站| 亚洲乱亚洲乱淫久久| 久久天天婷婷五月俺也去| 国产高潮国产高潮久久久| 久久本道久久综合伊人| 奇米综合四色77777久久| 国产精品日韩欧美久久综合| 久久精品成人欧美大片| 青青久久精品国产免费看| 大伊人青草狠狠久久| 久久久久久久精品妇女99| 欧美久久一级内射wwwwww.| 久久99国产精品一区二区| 日本五月天婷久久网站| 久久精品国产清自在天天线| 国产精品久久永久免费| 久久亚洲中文字幕精品有坂深雪 | 无码国内精品久久人妻| 欧美性猛交xxxx免费看久久久| 久久精品国产半推半就| 午夜精品久久久久久久久| 久久精品无码一区二区WWW| 国产精品99久久久久久宅男小说| 久久人妻少妇嫩草AV蜜桃| 久久国产V一级毛多内射| 久久99精品久久久久久9蜜桃| 久久久久免费精品国产| 青青草原1769久久免费播放| 久久99国产精品久久99| 国内精品久久久久久麻豆| 久久se这里只有精品| 伊人色综合久久天天网| 精品一二三区久久aaa片| 色综合久久综合中文综合网|