• <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
            久久精品无码一区二区app| 国产AⅤ精品一区二区三区久久| 亚洲天堂久久久| 国产偷久久久精品专区 | 久久精品成人欧美大片| 久久精品综合一区二区三区| 日韩美女18网站久久精品| 久久久久久亚洲AV无码专区| 久久精品中文字幕一区| 久久久久久亚洲AV无码专区| 久久影视国产亚洲| 久久久久四虎国产精品| 亚洲va久久久久| 国产成人综合久久精品尤物| 乱亲女H秽乱长久久久| 婷婷久久综合| 品成人欧美大片久久国产欧美... 品成人欧美大片久久国产欧美 | 久久久精品免费国产四虎| 欧美亚洲日本久久精品| 久久精品国产一区| 久久精品99久久香蕉国产色戒| 久久久国产精品| 99久久精品免费观看国产| 色婷婷综合久久久久中文| 久久99国产精品久久99小说| 国产巨作麻豆欧美亚洲综合久久| 国产成人久久AV免费| 国产亚洲色婷婷久久99精品| 亚洲人成精品久久久久| 国产精品久久久久久久app| 国产精品永久久久久久久久久| 欧美久久综合性欧美| 99久久精品国内| 久久精品国产亚洲av麻豆色欲| 久久婷婷五月综合成人D啪| 亚洲婷婷国产精品电影人久久| 久久一区二区三区免费| 久久这里都是精品| 77777亚洲午夜久久多人| 99精品国产免费久久久久久下载| 亚洲欧洲中文日韩久久AV乱码|