您的位置:首页 > 其它

匿名管道

2016-05-07 08:59 253 查看
//匿名管道
//实现父子进程间的进程通信
//发送简单少量无格式数据
#include <stdio.h>
#include <unistd.h>

int main()
{
pid_t child;
int fd[2];
int iRead;
int iWrite;
//create pipe
pipe(fd);
//create child
child = fork();
if(child == 0)
{
close(fd[1]);
while(1)
{
read(fd[0],&iWrite,sizeof(iWrite));
printf("Shu zi %d \n",iWrite);
}
close(fd[0]);
exit(0);
}
else
{
close(fd[0]);
while(1)
{
printf("shu ru\n");

scanf("%d",&iRead);
write(fd[1],&iRead,sizeof(iRead));
}
close(fd[1]);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: