标签:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
int fd[2];
pipe(fd);
pid_t pid = fork();
if(pid==0)
{
close(fd[0]);
write(fd[1],"Hello",6);
exit(0);
close(fd[1]);
}
pid_t pid2 = fork();
char buf[6]={0};
if(pid2==0)
{
close(fd[1]);
read(fd[0],buf,6);
printf(buf);
close(fd[0]);
exit(0);
}
else if(pid2>0)
{
close(fd[0]);
close(fd[1]);
exit(0);
}
}
标签:
原文地址:http://www.cnblogs.com/ZhangJinkun/p/4561661.html