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

            精品久久久久久中文字幕| 九九精品99久久久香蕉| 久久精品国产亚洲AV不卡| 久久综合综合久久狠狠狠97色88| 97精品久久天干天天天按摩 | 久久国产视屏| 国产精品久久网| 丰满少妇人妻久久久久久| 国产高潮国产高潮久久久91| 99久久免费只有精品国产| 久久综合色之久久综合| 久久人做人爽一区二区三区| 久久久噜噜噜久久中文福利| 伊人久久大香线焦综合四虎| 久久亚洲天堂| 久久久这里有精品中文字幕| 久久久久亚洲av综合波多野结衣 | 欧美与黑人午夜性猛交久久久 | 青青草原综合久久| 亚洲伊人久久大香线蕉苏妲己| 久久久久女教师免费一区| 久久人人爽人人爽人人av东京热 | 国产69精品久久久久9999APGF| 国内精品久久久久久99蜜桃| 久久久WWW成人| 亚洲精品久久久www| 韩国三级大全久久网站| 亚洲国产综合久久天堂| 成人久久综合网| AA级片免费看视频久久| 奇米综合四色77777久久| 中文精品久久久久国产网址| 亚洲乱码精品久久久久..| 一本久久久久久久| 久久综合伊人77777| 狠狠色伊人久久精品综合网| 久久精品国产清高在天天线| 热综合一本伊人久久精品| 亚洲午夜精品久久久久久人妖| 77777亚洲午夜久久多喷| 日韩美女18网站久久精品|