#include<stdio.h>#include<unistd.h>#include<string.h>#include<stdlib.h>intmain(){int fd[2];int pid;char buf[128];// int pipe(int pipefd[2]);if(pipe(fd)==-1){printf("creat pipe failed\n");}
pid =fork();if(pid<0){printf("creat child failed\n");}elseif(pid >0){sleep(3);//睡眠三秒,想让子进程出现,后出现父进程printf("this is father\n");close(fd[0]);write(fd[1],"hello from father",strlen("hello from father"));wait();}else{printf("this is cild\n");close(fd[1]);read(fd[0],buf,128);printf("read from father: %s\n",buf);exit(0);}return0;}