//http://blog.chinaunix.net/uid-24549279-id-71355.html
/*
============================================================================
Name : test.c
Author : blank
Version :
Copyright : Your copyright notice
Description : 程序清单8-3 8-4 演示不同的exit值
============================================================================
*/ #include "ourhdr.h"
#include <sys/wait.h> static void pr_exit(int status); int main(int argc, char *argv[])
{
pid_t pid;
int status; if ((pid = fork()) < ){
err_sys("fork error");
}else if(pid == ){
//child
exit();
} /*
* wait for child and print its status
*/
if (wait(&status) != pid){
err_sys("wait error");
} pr_exit(status); /*
* child generates SIGABRT
*/
if ((pid = fork()) < ){
err_sys("fork_error");
}else if (pid == ){
abort();
} /*
* wait for child and print its status
*/
if (wait(&status) != pid){
err_sys("wait error");
} pr_exit(status); if ((pid = fork()) < ){
err_sys("fork error");
}else if(pid == ){
// child divide by 0 generates SIGFPE
status/=;
} /*
* wait for child and print its status
*/
if (wait(&status) != pid){
err_sys("wait error");
} pr_exit(status);
} static void pr_exit(int status)
{
if (WIFEXITED(status)){
printf("normal termination, exit status = %d\n", WEXITSTATUS(status));
}else if (WIFSIGNALED(status)){
printf("abnormal termination, signal number=%d%s\n", WTERMSIG(status),
#ifdef WCOREDUMP
WCOREDUMP(status) ? " (core file generated )" : "");
#else
"");
#endif
}else if(WIFSTOPPED(status)){
printf("child stopped, signal number=%d\n", WSTOPSIG(status));
}
}

程序清单8-3 8-4 演示不同的exit值的更多相关文章

  1. 程序清单 8-8 exec函数实例,a.out是程序8-9产生的可执行程序

    /* ============================================================================ Name : test.c Author ...

  2. windows phone 8 开发系列(三)程序清单说明与配置

    一 清单文件内容介绍 当我们先建了一个项目之后,我们可以看到vs自动会为我们创建了很多文件,正常人都会先一个个去翻看下每个文件都是干啥的,都主要写了些啥,在这些文件中,在Properies目录下面,我 ...

  3. [C++ Primer Plus] 第11章、使用类(一)程序清单——重载 P408

    程序清单11.4~11.6(运算符重载——添加加法运算符) //1.h class Time { private: int hours; int minutes; public: Time(); Ti ...

  4. [C++ Primer Plus] 第10章、对象和类(一)程序清单——辨析三个const

    程序清单10.1+10.2+10.3 头文件stock.h #ifndef STOCK00_H_ //先测试x是否被宏定义过 #define STOCK00_H_ //如果没有宏定义,就宏定义x并编译 ...

  5. [C++ Primer Plus] 第9章、内存模型和名称空间(一)程序清单

    程序清单9.9(静态存储连续性.无链接性) #include<iostream> using namespace std; ; void strcount(const char *str) ...

  6. [C++ Primer Plus] 第8章、函数探幽(一)程序清单——内联、引用、格式化输入输出、模板、decltype

    程序清单8.1(inline内联函数) #include<iostream> using namespace std; inline double square(double x) {// ...

  7. [C++ Primer Plus] 第7章、函数(一)程序清单——递归,指针和const,指针数组和数组指针,函数和二维数组

    程序清单7.6 #include<iostream> using namespace std; ; int sum_arr(int arr[], int n);//函数声明 void ma ...

  8. [C++ Primer Plus] 第6章、分支语句和逻辑运算符(一)程序清单

    程序清单6.2 #include<iostream> using namespace std; void main() { char ch; cout << "Typ ...

  9. [C++ Primer Plus] 第4章、复合类型(一)程序清单——指针new和delete

    程序清单4.1 #include<iostream> using namespace std; void main(){ ]; yams[]=; yams[]=; yams[]=; ]={ ...

随机推荐

  1. Office版本差别引发的语法问题

    由于没有源代码,今天反编译了一个基于.NET的dll类库,再次遇到office版本差异问题,所以把它记录下来. 在反编译时,需要Aspose.Cells 5.3.1(Aspose是一套.NET类库,其 ...

  2. 关于ApplicationPoolIdentity

    一直以来IIS中的网站默认都是以network service在运行,但是从IIS7开始,默认会以ApplicationPoolIdentity运行. 这个账户比较特殊,是一种虚拟帐户,你无法在计算机 ...

  3. android Json详解

    Json:一种轻量级的数据交换格式,具有良好的可读和便于快速编写的特性.业内主流技术为其提供了完整的解决方案(有点类似于正则表达式 ,获得了当今大部分语言的支持),从而可以在不同平台间进行数据交换.J ...

  4. C语言接口与实现实例

    一个模块有两部分组成:接口和实现.接口指明模块要做什么,它声明了使用该模块的代码可用的标识符.类型和例程,实现指明模块是如何完成其接口声明的目标的,一个给定的模块通常只有一个接口,但是可能会有许多种实 ...

  5. 【读书笔记】iOS-属性列表

    一,在Cocoa中,有一类名为属性列表的对象,常简写为plist.这些列表包含Cocoa知道如何操作的一组对象.具体来讲,Cocoa如何知道将这们保存在文件中并进行加载.属性列表类包括NSArray, ...

  6. 二维码扫描利用ZBar实现

    上次是根据系统的属性自己封装的一个二维码扫描,这次给大家介绍一下基于ZBar集成的类似于QQ二维码扫描界面的二维码扫描的效果.                                     ...

  7. Monyer's Game 0~5关过关方法

    自从Monyer编写了这个通关小游戏,可谓是好事坏事参半吧! 好事是Monyer认识了许多电脑高手,包括netpatch.luoluo等,连LCX这种骨灰级选手也过来了,可谓是收获不小(所以既然我已经 ...

  8. img标签使用默认图片的一种方式

    基于html5提供的onerror这个时间属性.

  9. Jmeter代理录制脚本

    录制的原理: 1.LR/Jmeter录制是针对网络通讯协议层面的,它只关心客户端与服务器端的通讯包2.LR/Jmeter的并发测试实际上就是并发客户端与服务器端的通讯过程3.压力是通过多进程/多线程方 ...

  10. Oracle查看所有用户

    1.查看所有用户:select * from dba_users;   select * from all_users;   select * from user_users; 2.查看用户或角色系统 ...