码迷,mamicode.com
首页 > 其他好文 > 详细

捕捉段错误信号信号处理程序

时间:2015-06-03 15:12:03      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

//简单的捕捉段错误信号信号处理程序,通过signal来捕捉错误.

 

 

#include<stdio.h>
#include<signal.h>
#include<stdlib.h>
void handler(int s)
{
    if(s == SIGINT) printf("now got a interrupt signal  ");
    if(s == SIGSEGV) printf("now got a segmentation violation signal ");
    if(s == SIGILL) printf("now got an illegal instruction signal ");
    exit(1);
}
int main()
{
    int *p = NULL;
    signal(SIGINT, handler);
    signal(SIGSEGV,handler);
    signal(SIGILL, handler);
    *p = 0;
    return 0;
}

 

捕捉段错误信号信号处理程序

标签:

原文地址:http://www.cnblogs.com/lidabo/p/4548880.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!