#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define MAXLINE 4096
int main(int argc,char *argv[])
{
int n;
int fd[2];
pid_t pid;
char line[MAXLINE];
if(pipe(fd) < 0)
{
printf("pipe error!\n");
exit(1);
}
if((pid =fork()) < 0)
{
printf("fork error!\n");
exit(1);
}
else if(pid > 0)
{
close(fd[0]);
write(fd[1],"hello world\n",12);
}
else
{
close(fd[1]);
n = read(fd[0],line,MAXLINE);
write(STDOUT_FILENO,line,n);
}
exit(0);
}