Enable Core Dump On Linux

Outlines

  1. setup core-dump limit
  2. setup core-pattern
  3. prepare folder for core-dumps
  4. check bash limit is removed
  5. verify that everything works

 

Setup Resource Limit

First we need to setup resource limit at system-wide level.

  • edit /etc/security/limits.conf, add or un-comment this line
    *        soft    core    unlimited   # or number in KB
  • (optional) edit /etc/init.d/functions and add this line
    ulimit -S -c ${daemon_corefile_limit:-0} >/dev/null 2>&1
  • (centos/redhad only) edit /etc/sysconfig/init to enable core-dump globally
    DAEMON_COREFILE_LIMIT='unlimited'

 

Setup Core-Pattern

The current working directory is usually not a good place to save cores

  • the process might not have writing permission
  • the space might not enough
  • cwd might change during the running, and core might be dumped anytime
  • leave cores everywhere in the filesystem

Edit file /etc/sysctl.conf, add following lines

# setup core-pattern
fs.suid_dumpable = 1          # enable dumping suid app
kernel.core_uses_pid = 1      # append pid to the following string
kernel.core_pattern = /tmp/core  # core-dump prefix string
# the final core file will be /tmp/core.$pid

Let the settings take effect

sudo /sbin/sysctl -p

 

Prepare Folders for Cores

After setting core-patterns, don’t forget to create the folder that holds cores. The folder should be accessible for process that potentially create cores.

 

Check Bash limits

Resource limits of a process are inherited from its parent. The process can reduce but can’t increase the limit. Many shell profiles by default restrict core-dump ability. Check and remove/edit such restrictions like

ulimit -S -c 0 > /dev/null 2>&1

from profile of shell that launch the application

  • /etc/profile
  • ~/.profile
  • ~/.bashrc

 

Verify That Everything Works

  1. Logout and login
  2. Type ulimit -a to check core file size.
  3. Run any command and send it signal SIGSEGV while it is still running.
Advertisements