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

            人妻精品久久久久中文字幕69| 国产午夜免费高清久久影院| 亚洲午夜无码AV毛片久久| 亚洲国产精品无码久久久久久曰 | 久久国产精品成人片免费| 精品久久久久中文字幕日本| 国产A级毛片久久久精品毛片| 伊人久久五月天| 欧美日韩中文字幕久久伊人| 免费精品国产日韩热久久| 久久777国产线看观看精品| 亚洲国产精品嫩草影院久久| 亚洲成色999久久网站| 99久久精品国产一区二区| 国产精品久久久久aaaa| 狠狠色丁香久久婷婷综合图片| 久久99精品国产99久久6男男| 99精品久久精品一区二区| 国产午夜电影久久| 久久99国产综合精品女同| 久久婷婷五月综合成人D啪| 国产精品青草久久久久福利99 | 国产激情久久久久影院小草| 久久久久亚洲Av无码专| 久久婷婷国产剧情内射白浆| 久久国产三级无码一区二区| 狠狠色婷婷综合天天久久丁香| 中文精品久久久久人妻不卡| 精品国产乱码久久久久软件| 久久久免费观成人影院| 久久av免费天堂小草播放| 久久久久久亚洲精品不卡| 久久久久国色AV免费看图片| 久久强奷乱码老熟女网站| 久久久久亚洲AV成人网| 日韩精品久久久久久久电影| 久久受www免费人成_看片中文| 一级做a爰片久久毛片看看| 国产69精品久久久久APP下载| 丁香色欲久久久久久综合网| 久久亚洲精品国产精品|