#include <stdio.h>
#include <unistd.h>
#include <string.h>
int main()
{
int fd[2];
//int pipe(int pipefd[2]);
pid_t pid;
char buff[128];
if(pipe(fd)<0)
printf(“creat pipe error\n”);
if((pid = fork())<0)
printf(“creat child failed\n”);
else if(pid>0) {
printf(“this is father\n”);
close(fd[0]);
write(fd[1],“hellow word”,strlen(“hellow word”));
} else {
close(fd[1]);
read(fd[0],buff,128);
printf("%s\n",buff);
}
return 0;
}
创建无名管道
最新推荐文章于 2024-03-15 09:21:33 发布