• <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 老馬驛站 閱讀(2751) 評論(0)  編輯 收藏 引用 所屬分類: c++linux
            久久久无码精品亚洲日韩蜜臀浪潮| 99久久婷婷国产综合精品草原| 久久精品成人免费网站| 久久人人爽人人爽人人片AV高清 | 亚洲国产成人乱码精品女人久久久不卡 | 久久久久亚洲AV成人网人人软件| 国产精品久久精品| 国产91久久精品一区二区| 国产午夜福利精品久久2021| 国产精品18久久久久久vr| 国产精品久久久久久吹潮| 国产精品久久久久aaaa| 国产69精品久久久久99| 亚洲欧美精品一区久久中文字幕| 亚洲精品99久久久久中文字幕 | 久久久SS麻豆欧美国产日韩| 国产69精品久久久久久人妻精品| 国内精品人妻无码久久久影院导航 | 91麻精品国产91久久久久| 99久久精品免费| 久久久国产视频| 精品综合久久久久久888蜜芽| 国产精品99久久精品| 国产精品伦理久久久久久| 久久久久亚洲精品男人的天堂 | 久久福利资源国产精品999| 亚洲国产精品成人久久| 99久久国产主播综合精品| 久久笫一福利免费导航 | 一本久久综合亚洲鲁鲁五月天| 精品久久久无码21p发布| 久久久91精品国产一区二区三区| 久久久久无码专区亚洲av| 久久精品中文闷骚内射| 久久久久久久国产免费看| 精品久久久久久亚洲精品 | 久久精品国产精品青草| 伊人色综合久久天天人守人婷| 国产精品久久久久无码av| 午夜精品久久影院蜜桃| 国产精品久久99|