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

前端 未结 5 1757
醉梦人生
醉梦人生 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 20:02

    If you want to make an application dump it's core from another program, pretty much the only way to do it is via a signal. SEGV would be fine for this. Alternatively you can hook a debugger up to the program and freeze it and view it's registers and such without killing it.

    If you want to dump a core from within an application there are nicer ways to do it, like via an assert().

    So, no, it's not particularly wrong to send a SEGV to a program. You could also send things like SIGILL for illegal instruction, or a divide by zero signal. It's all fine.

提交回复
热议问题