您的位置:首页 > Web前端

父子进程间的单向管道通信

2010-01-02 17:17 330 查看
#include<stdio.h>
#include<errno.h>
#include<unistd.h>

int main()
{
int pid, pipeFD[ 2 ];
char buffer[ 100 ];
if ( pipe( pipeFD ) < 0 )
{
printf( "created pipe error/n" );
exit( -1 );
}
if( ( pid = fork() ) == 0 )
{
close( pipeFD[ 0 ] );
write( pipeFD[ 1 ], "hell", 13 );
write( STDOUT_FILENO, "write done/n", 11 ) ;
}
else
{
close( pipeFD[ 1 ] );
read( pipeFD[ 0 ], buffer, 100 );
printf( "%s/n", buffer );
waitpid( pid, NULL, 0 );
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  buffer null