• <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 閱讀(906) 評論(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国产综合精品女同| 国产精品欧美久久久久无广告| 中文字幕久久亚洲一区| 国产一区二区三区久久精品| 久久强奷乱码老熟女| 久久久噜噜噜久久中文福利| 欧美国产成人久久精品| 久久国产精品久久久| 777午夜精品久久av蜜臀| 66精品综合久久久久久久| 99久久精品免费看国产一区二区三区 | 久久99精品久久只有精品| 久久久91人妻无码精品蜜桃HD| 久久久久人妻精品一区二区三区 | WWW婷婷AV久久久影片| 久久久久人妻精品一区三寸蜜桃| 精品国产一区二区三区久久久狼| 国产精品综合久久第一页| 久久久久成人精品无码中文字幕| 久久无码高潮喷水| 久久亚洲AV永久无码精品| 国产精品免费久久久久久久久| 久久99热只有频精品8| 日韩精品久久久久久久电影蜜臀| 久久国内免费视频| 久久久久久久91精品免费观看| 精品视频久久久久| 久久精品一区二区影院 | 亚洲国产精品无码久久一线| 久久黄色视频| 日韩久久久久中文字幕人妻| 狠狠色丁香婷综合久久| 欧美亚洲国产精品久久蜜芽| 97精品国产97久久久久久免费| 女人香蕉久久**毛片精品| 色综合久久88色综合天天|