exit的状态
下面是一个实例,来演示不通的exit值
[cpp]
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
void pt_exit(int status)
{
if(WIFEXITED(status))
printf("nomal termination, exit status = %d\n",
WEXITSTATUS(status));
else if(WIFSIGNALED(status))
printf("abnomal termination, signal number = %d%s\n",
WTERMSIG(status), "");
else if(WIFSTOPPED(status))
printf("child stopped, signal number = %d\n",
WSTOPSIG(status));
}
int main(void)
{
pid_t pid;
int status;
if((pid = fork()) < 0)
printf("error: fork error.\n");
else if(pid == 0)
exit(7);
if(wait(&status) != pid)
printf("error: wait error.\n");
pt_exit(status);
if((pid = fork()) < 0)
printf("error: fork error.\n");
else if(pid == 0)
abort();
if(wait(&status) != pid)
printf("error: wait error.\n");
pt_exit(status);
if((pid = fork()) < 0)
printf("error: fork error.\n");
else if(pid == 0)
status /= 0;
if(wait(&status) != pid)
printf("error: wait error.\n");
pt_exit(status);
exit(0);
}
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
void pt_exit(int status)
{
if(WIFEXITED(status))
printf("nomal termination, exit status = %d\n",
WEXITSTATUS(status));
else if(WIFSIGNALED(status))
printf("abnomal termination, signal number = %d%s\n",
WTERMSIG(status), "");
else if(WIFSTOPPED(status))
printf("child stopped, signal number = %d\n",
WSTOPSIG(status));
}
int main(void)
{
pid_t pid;
int status;
if((pid = fork()) < 0)
printf("error: fork error.\n");
else if(pid == 0)
exit(7);
if(wait(&status) != pid)
printf("error: wait error.\n");
pt_exit(status);
if((pid = fork()) < 0)
printf("error: fork error.\n");
else if(pid == 0)
abort();
if(wait(&status) != pid)
printf("error: wait error.\n");
pt_exit(status);
if((pid = fork()) < 0)
printf("error: fork error.\n");
else if(pid == 0)
status /= 0;www.zzzyk.com
if(wait(&status) != pid)
printf("error: wait error.\n");
pt_exit(status);
exit(0);
}
作者:zhangjie201412
补充:软件开发 , C++ ,