Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

c

signals

core

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?

like image 916
Muru Avatar asked Apr 13 '11 11:04

Muru


2 Answers

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

like image 97
edA-qa mort-ora-y Avatar answered Oct 16 '22 10:10

edA-qa mort-ora-y


Yes. kill is somewhat misnamed -- it can send any signal. There are many uses for kill which don't result in the process being killed at all!

like image 36
Ernest Friedman-Hill Avatar answered Oct 16 '22 09:10

Ernest Friedman-Hill