Mac OS X,  Mac Security,  Mass Deployment,  Ubuntu

Managing Core Dumps

The core dump is a memory image of a processes in-core state that is written to the /cores directory by default and is named core followed by a . and then the pid number. So if a process with pid 87 crashes a file is written by default at /cores/core.87. The feature can be turned off using sysctl, along with the kern.coredump MIB, setting it to 0 (by default it’s 1).

sysctl kern.coredump=0

To turn it back on:

sysctl kern.coredump=1

Additionally, you can change the path that the files are written into, using sysctl along with the kern.corefile MIB. The corefile is an expression that by defualt writes core.%P where %P is the PID of the process whose memory image is being written. If you wanted to change the path for the corefiles to /cores2, you would run the following:

sysctl kern.corefile=/cores2/core.%P

To change it back to the default:

sysctl kern.corefile=/cores/core.%P

The sysctl command edits the state but doesn’t persist across reboots, so echo the above lines into /etc/sysctl.conf in order to have them be persistent. To disable core dumps:

echo 'kern.coredump=0' >> /etc/sysctl.conf

Or to change the location:

echo 'kern.corefile=/cores/core2.%P' >> /etc/sysctl.conf

Changing anything with regard to how core dumps would should typically be temporary. If there are no other customizations to sysctl.conf then you can undo these changes by removing the file; otherwise, simply remove the two lines and restart for the kernel to go back to its original state.