Linux: segmentation error handling and kernel dump

When my application crashes with a segmentation error, I would like to get a kernel dump from the system. I do this by tuning in front of the hand

ulimit -c unlimited 

I would also like to have an indication in the application logs that a segmentation error has occurred. I do this using sigaction() . However, if I do this, the signal does not reach its default processing, and the core dump is not saved.

How can I simultaneously dump a system core into a log line from my own signal handler?

+7
segmentation-fault linux signals coredump
May 22 '13 at 16:47
source share
2 answers

Answer: set sigaction with the flag SA_RESETHAND and just return from the handler. The same command is repeated again, causing the segmentation to repeat and calling the default handler.

+1
May 23 '13 at 03:19
source share
  • Overwrite the default signal handler for SIGSEGV to invoke a custom logging function.
  • After it is registered, restore and activate the default handler, which will create a core dump.

Here is an example program using signal :

 void sighandler(int signum) { myLoggingFunction(); // this is the trick: it will trigger the core dump signal(signum, SIG_DFL); kill(getpid(), signum); } int main() { signal(SIGSEGV, sighandler); // ... } 

The same idea should also work with sigaction .

Source: How to handle SIGSEGV, but also generate core dump

+5
Oct 11 '13 at 0:48
source share



All Articles