您的位置:首页 > 运维架构 > Linux

linux实验四---管道

2015-06-01 20:32 741 查看
#define MSGSIZE 25

main()
{
int pfd[2],pid;
static charmsgsend[MSGSIZE+1]=”Hi!Kid.\n”;
static charmsgrev[MSGSIZE+1];
if(pipe(pfd)==-1)
{
perror(“pipe”);
exit(1);
}
if((pid=fork())==0)
{
puts(“beforeread”);
read(pfd[0],msgrev,strlen(msgsend)+1);
puts(“readcompletely”);
puts(msgrev);
}
else
{
puts(“Parentsleeping......”);
sleep(2);
puts(“Parentwakeup......”);
write(pfd[1],msgsend,strlen(msgsend)+1);
}
exit(0);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux 管道