Friday, May 21, 2010

Naming core dump file

Linux Kernel 2.6 provides user an option to name the core dump file. User can define template in file /proc/sys/kernel/core_pattern for naming the core dump file. The template contains % specifiers that get substituted when core dump file is generated.
  • %% a single % character
  • %p PID of dumped process
  • %u (numeric) real UID of dumped process
  • %g (numeric) real GID of dumped process
  • %s number of signal causing dump
  • %t time of dump, expressed as seconds since the Epoch (00:00h, 1 Jan 1970, UTC)
  • %h hostname (same as nodename returned by uname(2))
  • %e executable filename (without path prefix)
  • %c core file size soft resource limit of crashing process (since Linux 2.6.24)
Example:
I want my core dump filename look something like this signal-no_pid_exe-name_timestamp.core. On Ubuntu machine:

userOne@shangri-la:~/myTests/coredump$ su
root@shangri-la:/home/userOne/myTests/coredump# echo '%s_%p_%e_%t.core' > /proc/sys/kernel/core_pattern
root@shangri-la:/home/userOne/myTests/coredump# exit
userOne@shangri-la:~/myTests/coredump$ cat /proc/sys/kernel/core_pattern
%s_%p_%e_%t.core

After running the culprit program coredump, I got
11_12945_coredump_1274446084.core file.

Simple and nice!

No comments:

Post a Comment