//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. 通过FTP连接Azure上的网站

    下载发布文件 使用记事本(或其他文本工具)打开 找到ftp连接地址以及用户名.密码 使用ftp工具进行连接 输入相应参数,连接即可

  2. 如何在 在SharePoint 2013/2010 解决方案中添加 ashx (HttpHandler)

    本文讲述如何在 在SharePoint 2013/2010 解决方案中添加 ashx (HttpHandler). 一般处理程序(HttpHandler)是·NET众多web组件的一种,ashx是其扩 ...

  3. linux中fork()函数详解(原创!!实例讲解) (转载)

     一.fork入门知识 一个进程,包括代码.数据和分配给进程的资源.fork()函数通过系统调用创建一个与原来进程几乎完全相同的进程, 也就是两个进程可以做完全相同的事,但如果初始参数或者传入的变量不 ...

  4. Android—Ormlite框架简单的操作数据库

    大家在Android项目中或多或少的都会使用数据库,为了提高我们的开发效率,当然少不了数据库ORM框架了,尤其是某些数据库操作特别频繁的app:本篇博客将详细介绍ORMLite的简易用法. 下面开始介 ...

  5. iOS网络-04-大文件下载

    大文件下载注意事项 若不对下载的文件进行转存,会造成内存消耗急剧升高,甚至耗尽内存资源,造成程序终止. 在文件下载过程中通常会出现中途停止的状况,若不做处理,就要重新开始下载,浪费流量. 大文件下载的 ...

  6. Mac显示隐藏文件的终端命令

    显示:defaults write com.apple.finder AppleShowAllFiles -bool true隐藏:defaults write com.apple.finder Ap ...

  7. 后台API服务的设计考虑

    我在<写在最前>里说过,后台API的文档至关重要.不过,文档只是外在表现形式,设计才是真正的灵魂.我在这篇博文主要介绍的就是我在后台开发过程中,设计API时的考虑.我只说他是考虑,因为很多 ...

  8. setInterval setTimeout clearInterval

    setTimeout() 只执行 code 一次.如果要多次调用,请使用 setInterval() 或者让 code 自身再次调用 setTimeout(). //第一次load的时候就先刷新一次 ...

  9. 【故障处理】CRS-1153错误处理

    [故障处理]CRS-1153错误处理 1  CRS-1153: There was an error setting Oracle Clusterware to rolling patch mode. ...

  10. Spring依赖注入三种方式详解

    在讲解Spring依赖注入之前的准备工作: 下载包含Spring的工具jar包的压缩包 解压缩下载下来的Spring压缩包文件 解压缩之后我们会看到libs文件夹下有许多jar包,而我们只需要其中的c ...