1 #include <unistd.h> 2 #include <stdio.h> 3 #include<sys/wait.h> 4 5 int main( void ) 6 { 7 int filedes[2]; 8 char buf[80]; 9 pid_t pid; 10 11 pipe( filedes ); 12 pid=fork(); 13 if (pid > 0) 14 { 15 printf( "This is in the father process. " ); 16 char s[] = "this is write by pipe. "; 17 write( filedes[1], s, sizeof(s) ); 18 close( filedes[0] ); 19 close( filedes[1] ); 20 } 21 else if(pid == 0) 22 { 23 printf( "This is in the child process. " ); 24 read( filedes[0], buf, sizeof(buf) ); 25 printf( "%s ", buf ); 26 close( filedes[0] ); 27 close( filedes[1] ); 28 } 29 30 waitpid( pid, NULL, 0 ); 31 return 0; 32 }