Search code examples
c++csignalscoredump

What is the correct way to force an app to core dump and quit?


I just came across some code which used the kill system call to send a SIGSEGV signal to an app. The rationale behind this was that this would force the app to core dump and quit. This seems so wrong to me, is this normal practice?


Solution

  • SIGQUIT is the correct signal to send to a program if you wish to produce a core dump. kill is the correct command line program to send signals (it is of course poorly named, since not all signals will kill the program).

    Note, you should not send random signals to the program, not all of them will produce a core dump. Many of them will be handled by the program itself, either consumed, ignored, or induce other processing. Thus sending a SIGSEGV is wrong.


    GCC Says: http://www.gnu.org/s/libc/manual/html_node/Termination-Signals.html

    POSIX/Unix Says: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/signal.h.html