进程通信:信号通信中的SIGABRT的验证测试
2013-01-15 22:52
204 查看
/******************************************************************************************************************
参考:
说明:主要是在程序中的合适地址加上abort函数它就会向调用它的进程发SIGABRT信号。
******************************************************************************************************************/
为了验证这个SIGABRT,也就是abort函数,想起来把前两天学习的东西都结合起来了有:fork();有wait();有execl();有abort()。主体思想就是运行一个根本就不存在的程序,让其运行abort()。从下边的运行结果来看它没有运行abort()以下的代码,因为这时子进程已经退出了,并在它生命的最后一刻它告诉了它我父进程一些信息--就是一个SIGABRT信号。这个信号有什么用? 其实也没有什么用,父进程也可以不鸟这个信号。这只是一方面,主要说的是如果父进程想知道这个子进程怎么了,怎么就死了,想破案的话就可以找这个类似飞机上的黑匣子一样。用这个信号来传递。还有验证结果是abort()只干掉了当前进程,从实验结果来看有干掉父进程。
运行结果:
参考:
说明:主要是在程序中的合适地址加上abort函数它就会向调用它的进程发SIGABRT信号。
******************************************************************************************************************/
为了验证这个SIGABRT,也就是abort函数,想起来把前两天学习的东西都结合起来了有:fork();有wait();有execl();有abort()。主体思想就是运行一个根本就不存在的程序,让其运行abort()。从下边的运行结果来看它没有运行abort()以下的代码,因为这时子进程已经退出了,并在它生命的最后一刻它告诉了它我父进程一些信息--就是一个SIGABRT信号。这个信号有什么用? 其实也没有什么用,父进程也可以不鸟这个信号。这只是一方面,主要说的是如果父进程想知道这个子进程怎么了,怎么就死了,想破案的话就可以找这个类似飞机上的黑匣子一样。用这个信号来传递。还有验证结果是abort()只干掉了当前进程,从实验结果来看有干掉父进程。
#include <stdio.h> #include <stdlib.h> #include <errno.h> #include <math.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include <signal.h> #include <string.h> void my_func(int sign_no) { if(sign_no == SIGABRT) { printf("I have get SIGABRT\n"); } } int main(void) { pid_t child; signal(SIGABRT, my_func); if((child=fork())==-1) { printf("Fork Error: %s\n", strerror(errno)); exit(1); } else { if(child == 0) { printf("the child process is run\n"); sleep(1); if((execl("fuck", "fuck",NULL)) == -1); abort(); printf("I am the child:%d\n", getpid()); exit(0); } else { wait(NULL); printf("the father process is run\n"); printf("I am the father: %d\n", getpid()); return 0; } } }
运行结果:
[root@localhost gcc]# ./a.out the child process is run I have get SIGABRT the father process is run I am the father: 30540 [root@localhost gcc]#
相关文章推荐
- 进程通信-信号通信
- 进程通信之信号
- 进程学习:进程间通信(传统通信方式)3.信号
- 笔记四:进程间的通信(信号)
- linux进程通信---几个发送信号的函数(kill,raise,alarm,pause)
- linux进程通信之信号
- 进程通信之信号量
- PHP进程通信基础之信号
- Linux进程通信--信号
- 苏嵌学习之进程通行二信号通信
- Linux进程通信之信号
- linux 进程通信-信号学习总结(1)
- Linux(九):进程通信IPC(三)之验证管道容量
- 进程间的信号通信
- linux进程通信----信号的处理
- Linux下信号通信实现A进程死循环输出A后被C进程处理输出C
- Linux进程通信之信号
- 【UNIX】什么是进程间FIFO通信以及信号通信
- 进程通信之信号的运用
- Linux 进程通信之 ——信号和信号量总结