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

前端 未结 5 1728
醉梦人生
醉梦人生 2021-01-12 19:19

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

5条回答
  •  攒了一身酷
    2021-01-12 19:58

    Richard Stevens (_Advanced Programming in the UNIX Environment) wrote:

    The generation of core is an implementation features of most Unix. It is not part of POSIX.1.

    He lists 12 signals whose default action is to terminate with a core (ANSI: SIGABRT, SIGFPE, SIGILL, SIGSEGV, POSIX: SIGQUIT, Other: SIGBUS, SIGEMT, SIGIOT, SIGSYS, SIGTRAP, SIGXCPU, SIGXFSZ), all of them are overwritable (the two signals which aren't overwritable are SIGKILL and SIGSTOP).

    I've never seen a way to generate a core which isn't the use of a default signal handler.

    So if your goal is to generate a core and stop, the best is to choose a signal whose default handler does the job (SIGSEGV does the job), reset the default handler for the signal if you are using it and then use kill.

提交回复
热议问题