#include <stdio.h>
#include<unistd.h>
int main()
{
int fd[2];
char buff[40];
char info[40];
int pid;
int cnt=0;
if(pipe(fd) < 0) printf("Pipe Error\n");
if((pid = fork()) < 0){
printf("Fork Error\n");
return 0;
}
else if(pid == 0) {
while(1){
close(fd[1]);
read(fd[0], buff, 40);
printf("son: %s\n", buff);
}
}
else{
while(1){
if(cnt > 65535) break;
close(fd[0]);
sprintf(info,"Hello-%d",cnt);
sleep(3);
printf("father: %d\n", cnt);
write(fd[1], info,40);
cnt ++;
}
}
return 0;
}