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 :”
我们看运行结果:
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 :”
我们看运行结果:
相关文章推荐
- VB.net结束进程
- Python基础 - from import方法与import方法的区别
- Unix环境编程学习笔记-----编程实例---- the normal exit1
- php 上传文件视频显示未找到文件错误
- JAVA Hibernate工作原理及为什么要用(hibernate 简介)
- C语言重要常用知识点梳理
- <精华帖>在Struts2中使用ValueStack、ActionContext、ServletContext、request、session等 .
- Python抓取糗事百科网页信息以及源码下载
- python 正则表达式
- java 多线程同步
- Ubuntu 14.04.3安装64位JDK1.7
- 私人Java最佳实践
- leveldb代码结构
- JAVA数据库连接-JDBC
- 过滤器与拦截器区别,action通配符配置,struts2数据验证
- 我的Bit路-C语言实现顺序
- C++程序员必须知道的5大内存区域
- while练习*登陆系统*大小写转换*None与“”
- Eclipse自动提示
- Eclipse自动提示