进程等待函数簇

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<sys/types.h>
 4 #include<sys/wait.h>
 5 #include<unistd.h>
 6 int main(void)
 7 {
 8     int status;
 9     pid_t pc,pr;
10     if((pc=fork())<0)
11     {
12         printf("failed to create a new process\n");
13         exit(1);
14     }
15     else if(pc==0)
16     {
17         printf("This is child process with pid of %d.\n",getpid());
18         exit(3);
19     }
20     else
21     {
22         pr=wait(&status);//注意这个参数值的使用
23         if(WIFEXITED(status))
24         {
25             printf("the child process %d exit normally.\nthe return code is %d\n",pr,WEXITSTATUS(status));            
26         }
27         else
28         {
29             printf("the child process %d exit abnormally.\n",pr);            
30         }
31     }
32     return 0;
33 }

 

你可能感兴趣的:(进程等待函数簇)