Configuring Core Files
core files are created when a program or an application terminates abnormally. The default location for a core file to be written is the current working directory. However, as the system administrator, you might want to configure the system so that all core files are written to a central location. This would make administration and management of core files much easier because core files can sometimes take up a significant amount of disk space.
What is a core file?
A core file is a point-in-time copy (snapshot) of the RAM allocated to a process. The copy is written to a more permanent medium, such as a hard disk. A core file is useful in analysing why a particular program crashed.
A core file is also a disk copy of the address space of a process, at a certain point in time. This information identifies items, such as the task name, task owner, priority, and instruction queue in execution at the time the core file was created.
Managing core files
You manage core files by using the coreadm
command:
coreadm [-g pattern] [-G content] [-i pattern] [-I content] [-d option...] [-e option...] coreadm [-p pattern] [-P content] [pid] coreadm -u
The following table lists the options available for the coreadm
command
Option | Description |
---|---|
-g pattern | Sets the global core file name pattern. |
-G content | Sets the global core file content using one of the description tokens. |
-i pattern | Sets the per-process core file name pattern. |
-I content | Sets the per-process core file name to content. |
-d option | Disables the specified core file option. |
-e option | Enables the specified core file option. |
-p pattern | Sets the per-process core file name pattern for each of the specified pids. |
-P content | Sets the per-process core file content to content. |
-u | Updates the systemwide core file options from the configuration file /etc/coreadm.conf. |
Running coreadm
with no options displays the current configuration, which you can determine by reading the file /etc/coreadm.conf
.
A core file name pattern consists of a file system pathname, along with embedded variables. These variables are specified with a leading % character. The values are then expanded when a core file is created. The following table lists valid pattern variables.
Option | Description |
---|---|
%p | Specifies the process ID (PID). |
%u | Specifies the effective user ID. |
%g | Specifies the effective group ID. |
%d | Specifies the executable file directory name. |
%f | Specifies the executable filename. |
%n | Specifies the system node name. This is the same as running uname -n. |
%m | Specifies the machine name. This is the same as running uname -m. |
%t | Specifies the decimal value of time, as the number of seconds since 00:00:00 January 1, 1970. |
-z | Specifies the name of the zone in which the process is executed (zonename). |
%% | Specifies the a literal % character. |
The -d
and -e
flags of the coreadm
command can take several options.
Option | Description |
---|---|
global | Allows core dumps, using the global core pattern. |
process | Allows core dumps, using the per-process core pattern. |
global-setid | Allows set-id core dumps, using the global core pattern. |
proc-setid | Allows set-id core dumps, using the per-process core pattern. |
log | Produces a syslog message when an attempt is made to generate a global core file. |
Example
To modify the core file configuration so that all files are dumped into the directory /cores
and named core
, followed by the system name and then the name of the program being run, we would execute:
- As
root
, use thecoreadm
command to display the current coreadm configuration:# coreadm global core file pattern: global core file content: default init core file pattern: core init core file content: default global core dumps: disabled per-process core dumps: enabled global setid core dumps: disabled per-process setid core dumps: disabled global core dump logging: disabled
- As root, issue the following command to change the core file setup:
# coreadm -i /cores/core.%n.%f
- Run
coreadm
again to verify that the change has been made permanent:# coreadm global core file pattern: global core file content: default init core file pattern: /cores/core.%n.%f init core file content: default global core dumps: disabled per-process core dumps: enabled global setid core dumps: disabled per-process setid core dumps: disabled global core dump logging: disabled