//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. H5前端面试题及答案(1)

    前几天去面试了一家公司,整下改公司的面试题. 1.新的 HTML5 文档类型和字符集是? HTML5 文档类型很简单: <!doctype html> HTML5 使用 UTF-8 编码示 ...

  2. elasticseach multi-field的实际用途

    下面是multi-field的介绍: multi_field 多域类型允许你对同一个值以映射的方式定义成多个基本类型 core_types . 这个非常有用,比如,如果你定义一个 string 类型的 ...

  3. Sharepoint 2013 关于"SPChange"简介

    在SharePoint中,我们经常会需要获取那些改变的项目,其实api为我们提供了SPChange对象,下面,我们通过列表简单介绍下这一对象. 1.创建一个测试列表,名字叫做“SPChangeItem ...

  4. SharePoint 2013 调用WCF服务简单示例

    内容比较简单,主要记录自己使用SharePoint 2013WCF服务遇到的小问题和小经验,分享给大家,希望能够给需要的人有所帮助.好吧,进入正题! 第一部分 SharePoint 2013调用自带W ...

  5. NSMutable sort排序

    Compare method Either you implement a compare-method for your object: - (NSComparisonResult)compare: ...

  6. android ButterKnife 解决重复findViewById

    简介: 程序员都是懒惰的,不想写一大堆像下面这样的代码 class ExampleActivity extends Activity { TextView title; TextView subtit ...

  7. 让 Popwindow 向上弹出

    /** * 获取父控件的位置y-popwindow的高度 = 应该显示的y坐标. x这里设置为center 不刻意指定坐标 注意:控件坐标永远是 左上角坐标! * * @param parent */ ...

  8. iOS设计模式之中介者模式

    中介者模式 基本理解 中介者模式又叫做调停者模式,其实就是中间人或者调停者的意思. 尽管将一个系统分割成许多对象通常可以增加可复用性,但是对象之间的连接又降低了可复用性. 如果两个类不必彼此直接通信, ...

  9. IOS 网络浅析-(五 xml解析)

    XML 可扩展标记语言 用于标记电子文件使其具有结构性的标记语言,可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言 易读性高,编码手写难度小,数据量大 NSXMLPars ...

  10. iOS 摇一摇

    - (void)viewDidLoad { [super viewDidLoad]; [[UIApplication sharedApplication] setApplicationSupports ...