|
- #include <stdio.h>
- #include <stdlib.h>
- #include <signal.h>
- char *g_pCH = NULL;
- char *g_pOther = NULL;
- void processSIGSEGV(int sig)
- {
- if(SIGSEGV != sig)
- {
- return;
- }
- g_pOther = g_pCH;
- sigset(SIGSEGV,processSIGSEGV);
- }
- int main()
- {
- sigset(SIGSEGV,processSIGSEGV);
- char *g_pOther= (char *)malloc(1024);
- printf("g_pOther is 0x%x.\n",g_pOther);
- g_pCH = g_pOther;
- g_pOther= (char *)0x33345;
- printf("g_pOther is 0x%x.\n",g_pOther);
- free(g_pOther);
- printf("memory freeed\n");
- return 0;
- }
复制代码
现在有一个棘手的进程core dump问题,已经知道是有段错误,也知道是哪一个指针引起的.
但是不知道指针在哪里被修改了,因此想写个小程序看能否捕获SIGSEGV信号,然后在信号处理函数中将错误指针重置,但是现在信号捕获后进程不退出,用gdb调试发现,free语句一直在执行,然后一直收到SIGSEGV段错误,陷入死循环.
请大侠看看,为什么信号处理函数中已经生效,但是还有SIGSEGV出现? |
|