Core Files in Linux
TASK
How do I set up Linux to produce core files?
SOLUTION
A core file is created when a program terminates unexpectedly, and can be useful for determining what caused the termination. By default, many Linux distributions do not produce core files when programs crash. This article describes how to override the default.
Using ulimit to set core file sizes
ulimit is a program, included in most Linux distributions, that allows you to specify many file size limits for the shell and all of its subprocesses.
For most distributions the core file size limitation is set to 0 to produce no core files at all. To find out the limit on the system in question, issue the command:
$ ulimit -c
If it is set to 0 then no core files are produced. To allow core files to be produced, set a core file size that is not 0:
$ ulimit -c 100000000000 or $ ulimit -c unlimited
The above commands set the core file size to 100 Mb or "unlimited", respectively.
Creating a test core file
To test whether or not a core file can be created, try the following command:
kill -s SIGSEGV $$
This command crashes your shell and produces a core file in the current directory.
Things to note about ulimit
ulimit sets shell variables. This means that the limits you set are valid only for that shell and all its subprocesses. If you want to set a limit system-wide, you need to ensure that ulimit sets its variables at startup. Usually it is sufficient to place the command in your .bash_profile, or whatever initialization file is used by your shells.
