免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1592 | 回复: 2
打印 上一主题 下一主题

[C] 调用 处理 内存SIGSEGV信号 陷入死循环 求指导 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-08-29 12:39 |只看该作者 |倒序浏览
#include        <stdio.h>
#include       <stdlib.h>
#include        <signal.h>
typedef void (*sighandler_t)(int);
//sighandler_t signal(int signum, sighandler_t handler);
void    sigexit_handler(int param){
        if(param == SIGSEGV)
                printf("SIGSEGV   :");
        printf("退出\n");
}

int     main(){
        int     a;
        signal(SIGTERM,sigexit_handler);
        signal(SIGINT,sigexit_handler);
        signal(SIGSEGV,sigexit_handler);
        a = *(int*)(0xFFFFFFFF);
        //raise(SIGINT);
        return  EXIT_SUCCESS;
}

执行后  循环调用  sigexit_handler函数,怎么回事
~                                                                                                                                                                     
~                          

论坛徽章:
59
2015年亚洲杯之约旦
日期:2015-01-27 21:27:392015年亚洲杯之日本
日期:2015-02-06 22:09:41拜羊年徽章
日期:2015-03-03 16:15:432015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015元宵节徽章
日期:2015-03-06 15:50:392015年亚洲杯之阿联酋
日期:2015-03-19 17:39:302015年亚洲杯之中国
日期:2015-03-23 18:52:23巳蛇
日期:2014-12-14 22:44:03双子座
日期:2014-12-10 21:39:16处女座
日期:2014-12-02 08:03:17天蝎座
日期:2014-07-21 19:08:47
2 [报告]
发表于 2012-08-29 13:05 |只看该作者

  1. void    sigexit_handler(int param){
  2.          if(param == SIGSEGV)
  3.                  printf("SIGSEGV   :");
  4.          printf("退出\n");
  5. }
复制代码
you do nothing about above code. while seg failt occurs, you handler be called, and just do nothing.
so that after your handler returned, the kernel try to resume the failed instrument.
of course it lead to a new failing.

seg failt always fatal error in a program. & it is very difficulty to fix (in many cast-- reach & near to all, it is impossible to fix), so,
don't try to fix a segment failing.

you can change your code to:

  1. void    sigexit_handler(int param){
  2.          if(param == SIGSEGV)
  3.                  printf("SIGSEGV   :");
  4.          printf("退出\n");
  5.          exit(-1);          // Fatal failure& can't be fixed.
  6. }
复制代码

论坛徽章:
0
3 [报告]
发表于 2012-08-29 16:00 |只看该作者
了解    谢谢folklore &goto回复 2# folklore


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP