I'm writing error handling code for a server on FreeBSD. For extremely serious errors I want to avoid data corruption by immediately terminating. That's easy, exit(3)
. Before I exit, I output my relevant variables that led me there. However, ideally, this termination would be accompanied by a .core
so that I could fully investigate what got me to this catastrophic (and likely hard to reproduce) state.
How can I force this to happen?
Core dumps are generated when the process receives certain signals, such as SIGSEGV, which the kernels sends it when it accesses memory outside its address space. Typically that happens because of errors in how pointers are used. That means there's a bug in the program. The core dump is useful for finding the bug.
kill -QUIT process_id
will cause a core dump from a running process (assuming that resource limits allow it).
Or see man 3 abort
for causing a program to dump itself.
Added: From an interactive shell, a running program can be made to abort with the quit key, usually Ctrl+\, which sends a SIGQUIT just as the more common Ctrl+C sends a SIGINT. This is identical to the kill -QUIT…
it's just easier to type if you are on the controlling terminal. See man 1 stty
if your default quit key is different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With