exit的不同值

来源:互联网 发布:淘宝联盟中的优惠券 编辑:程序博客网 时间:2024/06/07 03:11
 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 WCOREDUMP14             WCOREDUMP(statues) ? " (core file generated)" : "");15 #else16             "");17 #endif18     }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 }
原创粉丝点击