1 #include <unistd.h>
2 #include <sys/wait.h>
3
4 void pr_exit(int statues)
5 {
6 if(WIFEXITED(statues))
7 {
8 printf("normal trmination, exit statues = %d\n", WEXITSTATUS(statues));
9 }
10 else if(WIFSIGNALED(statues))
11 {
12 printf("abnormal termination, signal number = %d%s\n", WTERMSIG(statues),
13 #ifdef WCOREDUMP
14 WCOREDUMP(statues) ? " (core file generated)" : "");
15 #else
16 "");
17 #endif
18 }
19 else if(WIFSTOPPED(statues))
20 {
21 printf("child stopped, signal number = %d\n", WSTOPSIG(statues));
22 }
23 }
int main()
26 {
27 pid_t pid;
28 int ststues;
29
30 if((pid = fork()) < 0)
31 {
32 printf("fork error");
33 }
34 else if(pid == 0)
35 {
36 exit(7);
37 }
38
39 if(wait(&ststues) != pid)
40 {
41 printf("wait error");
42 }
43 pr_exit(ststues);
44
45 if((pid = fork()) < 0)
46 {
47 printf("fork error");
48 }
49 else if(pid == 0)
50 {
51 abort();
52 }
53
54 if(wait(&ststues) != pid)
55 {
56 printf("wait error");
57 }
58 pr_exit(ststues);
59
60 if((pid = fork()) < 0)
61 {
62 printf("fork error");
63 }
64 else if(pid == 0)
65 {
66 ststues /= 0;
67 }
68
69 if(wait(&ststues) != pid)
70 {
71 printf("wait error");
72 }
73 pr_exit(ststues);
74
75 exit(0);
76 }
exit的不同值
最新推荐文章于 2021-04-29 09:16:16 发布