//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. 通过GPS数据反向地理信息编码, 得到当前位置信息

    检查可用性 这属于基础知识, 不赘述, 总的来说,你的设备的支持要打开, 添加CoreLocation的framework, 引用头文件, 添加委托,然后, 好的实践是在使用前编程检查相关可用性: - ...

  2. mac下用ruby安装sass && webstorm下给scss文件添加watch

    1.安装rvm 先安装 [Xcode](http://developer.apple.com/xcode/) 开发工具,它将帮你安装好 Unix 环境需要的开发包 sudo curl -L https ...

  3. 【使用 DOM】使用 Document 对象

    Document 对象时通往DOM功能的入口,它向你提供了当前文档的信息,以及一组可供探索.导航.搜索或操作结构与内容的功能. 我们通过全局变量document访问Document对象,它是浏览器为我 ...

  4. Atitit.工作流系统的本质是dsl 图形化的dsl  4gl

    Atitit.工作流系统的本质是dsl 图形化的dsl  4gl 1. 工作流系统的本质是dsl 图形化的dsl  4gl1 2. 为什么每个项目系统都需要工作流1 3. 工作流dsl与java .n ...

  5. iOS设计模式之单例模式

    单例模式 基础理解 所有类都有构造方法,不编码则系统默认生成空的构造方法,若有显示定义的构造方法,默认的构造方法就会失效. 单例模式(Singleton):保证一个类仅有一个实例,并提供一个访问它的全 ...

  6. XCode中#pragma的使用

    为了能够快速定位到代码的目标位置,可以使用#pragma:  

  7. XCode升级到7后,规范注释生成器VVDocumenter插件没有用了,怎么办?

    Xcode更新到7之后,发现很多插件包括规范注释生成器VVDocumenter的插件都没法用了,找遍百度都没有找到成功解决这个问题的方法,然后我突发奇想,把注释也弄进代码模板里.虽然没有插件那样灵活: ...

  8. 基于AFNetWorking封装一个网络请求数据的类

    1.新建一个继承于NSObject类的类,在.h文件中 #import "AFHTTPRequestOperationManager.h" //定义两个block来接收请求成功和失 ...

  9. android network develop(3)----Xml Parser

    Normally, there are three type parser in android. Xmlpullparser, DOM & SAX. Google recomand Xmlp ...

  10. Effective Java 41 Use overloading judiciously

    The choice of which overloading to invoke is made at compile time. // Broken! - What does this progr ...