程序清单8-3 8-4 演示不同的exit值
//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值的更多相关文章
- 程序清单 8-8 exec函数实例,a.out是程序8-9产生的可执行程序
/* ============================================================================ Name : test.c Author ...
- windows phone 8 开发系列(三)程序清单说明与配置
一 清单文件内容介绍 当我们先建了一个项目之后,我们可以看到vs自动会为我们创建了很多文件,正常人都会先一个个去翻看下每个文件都是干啥的,都主要写了些啥,在这些文件中,在Properies目录下面,我 ...
- [C++ Primer Plus] 第11章、使用类(一)程序清单——重载 P408
程序清单11.4~11.6(运算符重载——添加加法运算符) //1.h class Time { private: int hours; int minutes; public: Time(); Ti ...
- [C++ Primer Plus] 第10章、对象和类(一)程序清单——辨析三个const
程序清单10.1+10.2+10.3 头文件stock.h #ifndef STOCK00_H_ //先测试x是否被宏定义过 #define STOCK00_H_ //如果没有宏定义,就宏定义x并编译 ...
- [C++ Primer Plus] 第9章、内存模型和名称空间(一)程序清单
程序清单9.9(静态存储连续性.无链接性) #include<iostream> using namespace std; ; void strcount(const char *str) ...
- [C++ Primer Plus] 第8章、函数探幽(一)程序清单——内联、引用、格式化输入输出、模板、decltype
程序清单8.1(inline内联函数) #include<iostream> using namespace std; inline double square(double x) {// ...
- [C++ Primer Plus] 第7章、函数(一)程序清单——递归,指针和const,指针数组和数组指针,函数和二维数组
程序清单7.6 #include<iostream> using namespace std; ; int sum_arr(int arr[], int n);//函数声明 void ma ...
- [C++ Primer Plus] 第6章、分支语句和逻辑运算符(一)程序清单
程序清单6.2 #include<iostream> using namespace std; void main() { char ch; cout << "Typ ...
- [C++ Primer Plus] 第4章、复合类型(一)程序清单——指针new和delete
程序清单4.1 #include<iostream> using namespace std; void main(){ ]; yams[]=; yams[]=; yams[]=; ]={ ...
随机推荐
- 关于SAP的视图类型
1 sap的视图的类型sap的视图的类型有五种 Database views (数据库视图):和数据库的视图形同,连接条件是必须自定义. Projection views(投影视图): 用于屏蔽一些字 ...
- anriod TabHost
package com.example.yanlei.mytk; import android.os.Bundle; import android.support.v7.app.AppCompatAc ...
- Linux平台Makefile文件的编写基础入门(课堂作业)
根据老师的要求,写一个超简单的makefile准备: 准备三个文件:file1.c, file2.c, file2.h file1.c: #include "file ...
- C语言指针传递详解
传递指针可以让多个函数访问指针所引用的对象,而不用把对象声明为全局可访问,要在某个函数中修改数据,需要用指针传递数据,当数据是需要修改的指针的时候,就要传递指针的指针,传递参数(包括指针)的时候,传递 ...
- iOS设计模式之命令模式
命令模式 基本理解 命令模式(Command),将一个请求封装为一个对象,从而使你可用不同的请求对客户端进行参数化:对请求队列或记录请求日志,以及支持客可撤离的操作. 苹果的Target-Action ...
- linux NFS服务器安装与配置 思路
一,nfs服务优缺点 NFS 是Network File System的缩写,即网络文件系统,可以让不同的客户端挂载使用同一个目录,作为共享存储使用,这样可以保证不同的节点客户端数据一致性,在集群架构 ...
- Oracle查看所有用户
1.查看所有用户:select * from dba_users; select * from all_users; select * from user_users; 2.查看用户或角色系统 ...
- 输入三个整数,xyz,最终以从小到大的方式输出。利用中间变量
<script>function bijiao(){ var x= parseFloat(document.getElementById("X").value); va ...
- PHP正则中的捕获组与非捕获组
今天遇到一个正则匹配的问题,忽然翻到有捕获组的概念,手册上也是一略而过,百度时无意翻到C#和Java中有对正则捕获组的特殊用法,搜索关键词有PHP时竟然没有相关内容,自己试了一下,发现在PHP中也是可 ...
- Plus One
Plus One https://leetcode.com/problems/plus-one/ Given a non-negative number represented as an array ...