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

            18禁黄久久久AAA片| 久久天天躁狠狠躁夜夜躁2O2O| 无码8090精品久久一区| 久久国产精品免费一区二区三区| 亚洲第一永久AV网站久久精品男人的天堂AV | 久久精品国产精品亚洲| 久久久久亚洲爆乳少妇无| 国产色综合久久无码有码| 久久国产色AV免费观看| 色偷偷88欧美精品久久久| 精品人妻伦九区久久AAA片69| 国内精品久久久久久野外| 色欲综合久久躁天天躁| 久久免费的精品国产V∧| 国产福利电影一区二区三区久久老子无码午夜伦不 | 99久久免费国产精品热| 国产精品嫩草影院久久| 久久99这里只有精品国产| 久久精品国产亚洲AV蜜臀色欲| 国产综合久久久久久鬼色| 亚洲第一永久AV网站久久精品男人的天堂AV| 一个色综合久久| 久久久久久久久久久精品尤物| 国产V亚洲V天堂无码久久久| 99久久人妻无码精品系列蜜桃| 欧美麻豆久久久久久中文| 国产精品一区二区久久| 久久不见久久见免费影院www日本| 精品国产乱码久久久久软件| 国产精品久久国产精麻豆99网站| 伊人久久无码精品中文字幕| 国产精品免费久久| 香蕉久久夜色精品国产小说| 麻豆成人久久精品二区三区免费| 久久久久无码中| 欧美精品福利视频一区二区三区久久久精品 | 国产成人综合久久综合| 性欧美丰满熟妇XXXX性久久久| 久久亚洲精品国产亚洲老地址| 99久久国产免费福利| 无码日韩人妻精品久久蜜桃 |