• <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>
            隨筆-167  評論-8  文章-0  trackbacks-0
            pipe(建立管道)

            表頭文件 #include<unistd.h>
            定義函數(shù) int pipe(int filedes[2]);
            函數(shù)說明
                pipe()會建立管道,并將文件描述詞由參數(shù) filedes 數(shù)組返回。
                filedes[0]為管道里的讀取端,所以pipe用read調(diào)用的
                filedes[1]則為管道的寫入端。
                
            返回值:  若成功則返回零,否則返回-1,錯誤原因存于 errno 中。
            錯誤代碼:
                EMFILE 進(jìn)程已用完文件描述詞最大量
                ENFILE 系統(tǒng)已無文件描述詞可用。
                EFAULT 參數(shù) filedes 數(shù)組地址不合法。

            #include <unistd.h>
            #include <stdio.h>

            int main( void )
            {
                int filedes[2];
                char buf[80];
                pid_t pid;
               
                pipe( filedes );
               
                if ( (pid=fork()) > 0 )
                {
                    printf( "This is in the father process,here write a string to the pipe.\n" );
                    char s[] = "Hello world , this is write by pipe.\n";
                    write( filedes[1], s, sizeof(s) );
                    close( filedes[0] );
                    close( filedes[1] );
                }
                else
                {
                    printf( "This is in the child process,here read a string from the pipe.\n" );
                    read( filedes[0], buf, sizeof(buf) );
                    printf( "%s\n", buf );
                    close( filedes[0] );
                    close( filedes[1] );
                }
               
                waitpid( pid, NULL, 0 );
               
                return 0;
            }


            [root@localhost src]# gcc pipe.c
            [root@localhost src]# ./a.out
            This is in the child process,here read a string from the pipe.
            This is in the father process,here write a string to the pipe.
            Hello world , this is write by pipe.
            posted on 2010-06-14 18:19 老馬驛站 閱讀(2759) 評論(0)  編輯 收藏 引用 所屬分類: c++linux
            99热成人精品免费久久| 久久精品成人免费观看97| 波多野结衣AV无码久久一区| 欧美精品乱码99久久蜜桃| 精品久久久久久久国产潘金莲| 亚洲欧美成人综合久久久| 国产精品美女久久久m| 国产精品99久久久久久宅男| 亚洲国产成人精品女人久久久 | 久久人人爽人人爽人人片AV不| 久久99中文字幕久久| 久久久WWW免费人成精品| 日产精品久久久久久久性色| 色综合久久88色综合天天| 精品人妻伦九区久久AAA片69| 久久精品国产69国产精品亚洲| 久久精品青青草原伊人| 久久久久四虎国产精品| 成人综合久久精品色婷婷| 日韩精品久久久久久| 亚洲AV日韩精品久久久久| 一级做a爰片久久毛片毛片| 91亚洲国产成人久久精品| 久久久无码精品亚洲日韩按摩 | 亚洲国产精品无码久久久不卡| 国内精品久久久久影院网站| 亚洲AV无码久久精品狠狠爱浪潮| 久久久精品久久久久久| 97精品伊人久久大香线蕉app| 国内精品伊人久久久久AV影院| 久久婷婷午色综合夜啪| 亚洲欧美久久久久9999| 久久精品国产99国产精品| 久久综合九色综合97_久久久| 久久99精品久久久久子伦| 久久久久av无码免费网| 亚洲精品美女久久久久99小说| 免费精品久久天干天干| 热久久最新网站获取| 久久久久国产精品人妻| 99久久夜色精品国产网站|