Shell – Exit status on core dump

core-dumpshell-script

When a process dumps core, does it set any particular exit code? Alternatively, is there a way to detect if core was dumped in a shell script.

I have shell script that fires a job which occasionally dumps the core. If my job dumps the core, I would like to modify the shell script so that next lines can check status and inform others interested that the job dumped core.

We save core dumps and do analyse it. This right now is done by simple find command. If I can check if one of the lines in my shell script caused core dump, I can diagnose the problems much faster.

On ubuntu 12.04.

Best Answer

In practice, a core dump will automatically be produced when the process is terminated by some signal, and the exit code will be determined by the signal (128 + signal_value), and under Linux, the signals can be at least: SIGQUIT (3), SIGILL (4), SIGABRT (6), SIGFPE (8), SIGSEGV (11). See the signal(7) man page for a more complete list. A core dump will not always be produced; see some circumstances in the core(5) man page.

Note: In languages that have full access to the wait system call (but this is not the case of POSIX shell scripts), you can use WCOREDUMP (available under Linux), which returns true if the child produced a core dump. See the wait(2) man page for more information.

Related Question