#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;
}
Linux下父子进程匿名管道通信
最新推荐文章于 2023-04-18 21:28:28 发布