/*pipe返回2个文件描述符指向管道,fd[0]指向管道的读,fd[1]指向管道的写*/
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
/*anonymous pipe*/
main()
{
int fd[2];
pipe(fd);
pid_t r;
if(r=fork())
{
close(fd[0]);
int i=1;
while(1)
{
sleep(1);
write(fd[1],&i,4);
i++;
}
}else{
close(fd[1]);
int a;
sleep(2);
while(1)
{
read(fd[0],&a,4);
printf("%d\n",a);
}
}
}