#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
main()
{ int x,fd[2];
char buf[30],s[30];
pipe(fd);
while ((x=fork())==-1);
if (x==0)
{
close(fd[0]);
printf("Child Process!\n");
strcpy(buf,"This is an example\n");
write(fd[1],buf,30);
exit(0);
}
else{
close(fd[1]);
printf("Parent Process!\n");
read(fd[0],s,30);
printf("%s\n",s);
}
}
/******************实验二第一段代码***********************/