Index ¦ Archives ¦ Atom

Testing if core dumps are enabled correctly

The problem

Core dumps are extremely useful for debugging purposes. However, it is often non-trivial to enable them as many production systems require twiddling with some configuration options to get core dumps working (most notably, the kernel.core_pattern sysctl, and the core file size setable with ulimit -c \<some value, or unlimited>). Most articles on the web cover this. What they don't cover is how to test if core dumps are working correctly. In non-production systems, one could simply crash the target process to find out. However, on production systems, that is unacceptable. So how do we test?

A possible solution

The following C program is extremely useful for testing core dumps:

float main() {
    return 1/0;
}

Compile the program:

gcc -o crash crash.c

And run it. If core dumps are enabled correctly, you'll see:

./crash
Floating point exception (core dumped)

Note the (core dumped) at the end, indicating a core dump was written and is accessible for debugging. If core dumps are not correctly enabled, you will only see the following output:

./crash
Floating point exception

Caveats

Please note that ulimits are often set per-user and per-session, and therefore, it is essential to test ulimits as the user that is going to run the application that is crashing unexpectedly.

© Bruno Henc. Built using Pelican. Theme by Giulio Fidente on github.