开发者

Generate core dump as well as text dump linux

If I only set coredump limit to unlimted. Core dump file is getting generated by linux. But If I do but signal handling as well as set core dump li开发者_如何学Gomit to unlimit. Linux doesn't generate core dump.

signal(SIGINT, SignalHandler);
signal(SIGSEGV, SignalHandler);

How to generate both text dump as well as core dump in linux ?


Set the signal handler to one shot mode (using the SA_RESETHAND flag to sigaction(2) for example) and call abort() at the end of your custom SIGINT/SIGSEGV signal handler.


Using the raise() function worked for me to catch crash info and dump core info.

https://www.man7.org/linux/man-pages/man3/raise.3.html

Register your signals as always, but also set the SA_RESETHAND flag (one shot call) with an OR:

sa.sa_flags = SA_SIGINFO | SA_RESETHAND;

https://www.man7.org/linux/man-pages/man2/sigaction.2.html

If you set that flag, once the signal handler is called your handling function is replaced by the default handling function the next time the same signal is received.

So, the first time a signal arrives, parse your signal info and do whatever needed within your signal handler. Before your handler is over, call raise().

void signalHandler(int receivedSignal, siginfo_t* info, void* args)
{
    /* Parse args and info as you wish */
    ...
    /* Re-trigger the same signal, but now the kernel or systemd will handle it 
       and dump the core status */
    raise(receivedSignal);
}

raise() will trigger the same signal that you just handled but as the signal handler function was one shot, your process will now ignore the repeated signal. The kernel or systemd will catch the signal this time and generate a core dump.

In my case, the crash info in the signal handler and the crash info in the core dump do match if raise() is used.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜