不要过于沉溺过去,也不要过于畅想未来,把握现在!

进程创建

 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.\n" );
16         char s[] = "this is write by pipe.\n";
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.\n" );
24         read( filedes[0], buf, sizeof(buf) );
25         printf( "%s\n", buf );
26         close( filedes[0] );
27         close( filedes[1] );
28     }
29 
30     waitpid( pid, NULL, 0 );
31     return 0;
32 }

 

posted @ 2015-03-22 20:00  coding_yuan  阅读(109)  评论(0编辑  收藏  举报

不要过于沉溺过去,也不要过于畅想未来,把握现在!