您的位置:首页 > 编程语言

Unix环境编程学习笔记-----编程实例---- the normal exit2

2015-11-21 20:30 274 查看
NORMAL 2:

THESOURCE CODE:

#include<unistd.h>

#include<errno.h>

#include<sys/types.h>

#include<sys/wait.h>

#include<stdio.h>

#include<stdlib.h>

int main()

{

intPpid_t,Spid_t,rpid_t;

inttmpstatus;

Spid_t=fork();

if(Spid_t<0)

{

perror("forkerror");

_exit(-1);

}elseif(Spid_t==0)

{

//子进程要做的事。

printf("subprocess is going to over!\n");

_exit(2);//wheni change the doc what will happen ???? example : _exit(2) ???

}

else

{

//父进程要做的事。

//父进程获取子进程的结束状态,并打印出来

//我先使用waitpid

rpid_t=waitpid(Spid_t,&tmpstatus,NULL);

//如果正常推出则打印出进程终止装填的编号 WIFEXITED(status)

if(WIFEXITED(tmpstatus))

{

printf("the status's value is :%d\n",WEXITSTATUS(tmpstatus));

}

else if(WSTOPSIG(tmpstatus)) //判断子进程是不是由信号杀死,如果是打印该信号值。

printf("thesignal value is :%d \n",WTERMSIG(tmpstatus));

_exit(2);

}

return0;

}

此时,我们传给_exit的值是2

“_exit(2);//wheni change the doc what will happen ???? example :”

我们看运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: