Linux:处理分段错误并获取核心转储 [英] Linux: handling a segmentation fault and getting a core dump

查看:121
本文介绍了Linux:处理分段错误并获取核心转储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的应用程序因分段错误而崩溃时,我想从系统中获取核心转储.我是通过事先配置来实现的

When my application crashes with a segmentation fault I'd like to get a core dump from the system. I do that by configuring before hand

ulimit -c unlimited

我还想在我的应用程序日志中指出发生了分段错误.我通过使用 sigaction() 来做到这一点.但是,如果我这样做,该信号将无法达到其默认处理,并且不会保存核心转储.

I would also like to have an indication in my application logs that a segmentation fault has occured. I do that by using sigaction(). If I do that however, the signal does not reach its default handling and a core dump is not saved.

如何让两个系统核心同时从自己的信号处理程序中转出一条日志行?

How can I have both the system core dump an a log line from my own signal handler at the same time?

推荐答案

答案:用标志SA_RESETHAND设置sigaction,然后从处理程序中返回.再次发生同一条指令,再次导致分段错误并调用默认处理程序.

The answer: set the sigaction with flag SA_RESETHAND and just return from the handler. The same instruction occurs again, causing a segmentation fault again and invoking the default handler.

这篇关于Linux:处理分段错误并获取核心转储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆