linux 为什么 没有生成core文件? 之二
来源:互联网 发布:天天向上网络 编辑:程序博客网 时间:2024/06/02 00:49
前文转了两篇简单的linux下进程crash后生成core文件的文章,包括信号、core机制的简述、没有生成core文件原因的排查,以及利用core文件调试定位crash point。
但我遇到的问题在前面的文章中还是无解。后来测试后发现,是因为代码中安装了
一:
但我遇到的问题在前面的文章中还是无解。后来测试后发现,是因为代码中安装了
SIGSEGV信号处理函数,在信号处理函数中打印堆栈信息。所以这时进程收到
SIGSEGV后,系统不再自动生成core文件。所以问题变成:手动处理
SIGSEGV信号后,怎么样让系统还生成core文件?或者:
How to handle SICSEGV, but also generate a core dump?
网上查了会,收到3种相关解决方案。一:
二:#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
void sighandler(int signum)
{
printf("Process %d got signal %d\n", getpid(), signum);
signal(signum, SIG_DFL);
kill(getpid(), signum);
}
int main()
{
signal(SIGSEGV, sighandler);
printf("Process %d waits for someone to send it SIGSEGV\n",
getpid());
sleep(1000);
return 0;
}
void segfaulthandler(int parameter){ char gcore[50]; sprintf(gcore, "gcore -s -c \"core\" %u", getpid()); system(gcore); exit(1);}
int main(void){ signal(SIGSEGV, segfaulthandler);}
三:/*
Handler functions that terminate the program are typically used to causeorderly cleanup or recovery from program error signals and interactiveinterrupts.
The cleanest way for a handler to terminate the process is to raise thesame signal that ran the handler in the first place. Here is how to dothis
*/
volatile sig_atomic_t fatal_error_in_progress = 0;voidfatal_error_signal (int sig){ /* Since this handler is established for more than one kind of signal, it might still get invoked recursively by delivery of some other kind of signal. Use a static variable to keep track of that. */ if (fatal_error_in_progress) raise (sig); fatal_error_in_progress = 1; /* Now do the clean up actions: - reset terminal modes - kill child processes - remove lock files */ ... /* Now reraise the signal. Since the signal is blocked, it will receive its default handling, which is to terminate the process. We could just callexit
orabort
, but reraising the signal sets the return status from the process correctly. */ raise (sig);}
经过验证,发现前两种方法能生成core,但是core文件的堆栈信息不对,已经不是crash时的堆栈信息。第三种方法似乎没有用...
由于时间紧,究竟什么原因我还没有仔细分析,先留个记录吧
知道原因的朋友请留言,谢谢!!
0 0
- linux 为什么 没有生成core文件? 之二
- 为什么没有产生core 文件
- linux为什么没有产生core 文件 问题分析
- Linux 生成 core文件
- linux core文件生成配置
- Linux生成core dump文件
- Linux之CORE文件
- Linux之core 文件
- Linux生成core文件、core文件路径设置
- Linux生成core文件、core文件路径设置
- Linux生成core文件、core文件路径设置
- Linux生成core文件、core文件路径设置
- Linux生成core文件、core文件路径设置
- 为什么core开关打开了, 没有产生core文件呢?------又是磁盘文件满了
- Linux core文件生成及设置
- Linux下如何生成core dump文件
- Linux下如何生成core dump文件
- linux 允许生成 core dump文件开关
- CentOS yum安装nginx
- linux CentOS 安装DDD调试器详解
- Windows 查询系统位数 32位还是64位
- linux template error: explicit specialization in non-namespace scope
- linux 安装subversion svn Option expected
- linux 为什么 没有生成core文件? 之二
- VS 2005 查找功能无法使用的解决办法 VS2005重新配置
- /etc/sysconfig/network: No such file or directory
- undefined reference to `SSL_get_current_cipher\' 链接OpenSSL库 -lssl
- svn 不显示图标状态
- Deep Learning(深度学习)学习笔记整理系列之(四)
- [转] std::_Copy_impl
- error C2039: \'NotifyWinEvent\' : is not a member of \'`global namespace\'\'
- [转]Centos 网络配置(手动设置和自动获取)IP的方法