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

Linux下父子进程匿名管道通信

2017-04-20 10:30 211 查看
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
int main()
{
int fd[2];
char buf[30],str[30];
pipe(fd);
pid_t pid1=fork();
if(pid1==0)
{sprintf(buf,"this an example\n");
printf("child is running,please input words!\n");
write(fd[1],buf,30);
sleep(3);
}
else
{wait(5);
read(fd[0],str,30);
printf("%s\n",str);}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: