• <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>
            定義函數 int pipe(int filedes[2]);
            函數說明
                pipe()會建立管道,并將文件描述詞由參數 filedes 數組返回。
                filedes[0]為管道里的讀取端,所以pipe用read調用的
                filedes[1]則為管道的寫入端。
                
            返回值:  若成功則返回零,否則返回-1,錯誤原因存于 errno 中。
            錯誤代碼:
                EMFILE 進程已用完文件描述詞最大量
                ENFILE 系統已無文件描述詞可用。
                EFAULT 參數 filedes 數組地址不合法。

            #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 老馬驛站 閱讀(2769) 評論(0)  編輯 收藏 引用 所屬分類: c++linux
            久久久无码一区二区三区| 香港aa三级久久三级老师2021国产三级精品三级在| 色综合久久综合中文综合网| 欧美久久综合九色综合| 久久久综合香蕉尹人综合网| 久久久精品久久久久特色影视| 亚洲国产精品成人AV无码久久综合影院| 亚洲熟妇无码另类久久久| 久久精品一区二区三区AV| 久久综合综合久久综合| 99re久久精品国产首页2020| 久久91精品国产91久久户| 99久久精品免费| 亚洲国产精品成人久久蜜臀 | 精品综合久久久久久97超人| 99re久久精品国产首页2020| 国产成人精品久久一区二区三区av| 99热热久久这里只有精品68| 婷婷久久综合九色综合绿巨人 | 亚洲欧美成人综合久久久| 久久精品国产99久久久| 久久精品国产清自在天天线| 偷偷做久久久久网站| 精品久久久噜噜噜久久久| 久久精品无码一区二区app| 欧美日韩精品久久久久| 狠狠色噜噜狠狠狠狠狠色综合久久| 国产高清国内精品福利99久久| 中文成人久久久久影院免费观看| 久久久婷婷五月亚洲97号色| 久久久久国产视频电影| 无码AV中文字幕久久专区| 久久久久国产亚洲AV麻豆| 99久久无码一区人妻a黑| 无码AV中文字幕久久专区| 久久久久亚洲精品无码网址| 久久男人Av资源网站无码软件| 武侠古典久久婷婷狼人伊人| 国内精品久久久久久久久| 久久国产精品成人片免费| 青青草原综合久久大伊人|