exit的不同值

 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 }




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值