A process can set its soft RLIMIT_CORE resource limit to place an upper limit on the size of the core dump file that will be produced if it receives a "core dump" signal; see getrlimit(2) for details.
There are various circumstances in which a core dump file is not produced:
In addition, a core dump may exclude part of the address space of the process if the madvise(2) MADV_DONTDUMP flag was employed.
- %%
- a single % character
- %c
- core file size soft resource limit of crashing process (since Linux 2.6.24)
- %d
- dump mode--same as value returned by prctl(2) PR_GET_DUMPABLE (since Linux 3.7)
- %e
- executable filename (without path prefix)
- %E
- pathname of executable, with slashes (aq/aq) replaced by exclamation marks (aq!aq) (since Linux 3.0).
- %g
- (numeric) real GID of dumped process
- %h
- hostname (same as nodename returned by uname(2) )
- %p
- PID of dumped process, as seen in the PID namespace in which the process resides
- %P
- PID of dumped process, as seen in the initial PID namespace (since Linux 3.12)
- %s
- number of signal causing dump
- %t
- time of dump, expressed as seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC)
- %u
- (numeric) real UID of dumped process
A single % at the end of the template is dropped from the core filename, as is the combination of a % followed by any character other than those listed above. All other characters in the template become a literal part of the core filename. The template may include aq/aq characters, which are interpreted as delimiters for directory names. The maximum size of the resulting core filename is 128 bytes (64 bytes in kernels before 2.6.19). The default value in this file is "core". For backward compatibility, if /proc/sys/kernel/core_pattern does not include "%p" and /proc/sys/kernel/core_uses_pid (see below) is nonzero, then .PID will be appended to the core filename.
Since version 2.4, Linux has also provided a more primitive method of controlling the name of the core dump file. If the /proc/sys/kernel/core_uses_pid file contains the value 0, then a core dump file is simply named core. If this file contains a nonzero value, then the core dump file includes the process ID in a name of the form core.PID.
Since Linux 3.6, if /proc/sys/fs/suid_dumpable is set to 2 ("suidsafe"), the pattern must be either an absolute pathname (starting with a leading aq/aq character) or a pipe, as defined below.
The value in the file is a bit mask of memory mapping types (see mmap(2) ). If a bit is set in the mask, then memory mappings of the corresponding type are dumped; otherwise they are not dumped. The bits in this file have the following meanings:
- bit 0
- Dump anonymous private mappings.
- bit 1
- Dump anonymous shared mappings.
- bit 2
- Dump file-backed private mappings.
- bit 3
- Dump file-backed shared mappings.
- bit 4 (since Linux 2.6.24)
- Dump ELF headers.
- bit 5 (since Linux 2.6.28)
- Dump private huge pages.
- bit 6 (since Linux 2.6.28)
- Dump shared huge pages.
By default, the following bits are set: 0, 1, 4 (if the CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS kernel configuration option is enabled), and 5. The value of this file is displayed in hexadecimal. (The default value is thus displayed as 33.)
Memory-mapped I/O pages such as frame buffer are never dumped, and virtual DSO pages are always dumped, regardless of the coredump_filter value.
A child process created via fork(2) inherits its parent’s coredump_filter value; the coredump_filter value is preserved across an execve(2) .
It can be useful to set coredump_filter in the parent shell before running a program, for example:
$ echo 0x7 > /proc/self/coredump_filter$ ./some_program
This file is provided only if the kernel was built with the CONFIG_ELF_CORE configuration option.
In Linux versions up to and including 2.6.27, if a multithreaded process (or, more precisely, a process that shares its memory with another process by being created with the CLONE_VM flag of clone(2) ) dumps core, then the process ID is always appended to the core filename, unless the process ID was already included elsewhere in the filename via a %p specification in /proc/sys/kernel/core_pattern. (This is primarily useful when employing the obsolete LinuxThreads implementation, where each thread of a process has a different PID.)
$ cc -o core_pattern_pipe_test core_pattern_pipe_test.c$ suPassword: # echo dq|$PWD/core_pattern_pipe_test %p \" /proc/sys/kernel/core_pattern# exit$ sleep 100^\ # type control-backslashQuit (core dumped) $ cat core.infoargc=5 argc[0]=</home/mtk/core_pattern_pipe_test> argc[1]=<20575> argc[2]=<UID=1000> argc[3]=<GID=100> argc[4]=<sig=3> Total bytes in core dump: 282624
/* core_pattern_pipe_test.c */ #define _GNU_SOURCE #include <sys/stat.h> #include <fcntl.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #define BUF_SIZE 1024 int main(int argc, char *argv[]) { int tot, j; ssize_t nread; char buf[BUF_SIZE]; FILE *fp; char cwd[PATH_MAX]; /* Change our current working directory to that of the crashing process */ snprintf(cwd, PATH_MAX, "/proc/%s/cwd", argv[1]); chdir(cwd); /* Write output to file "core.info" in that directory */ fp = fopen("core.info", "w+"); if (fp == NULL) exit(EXIT_FAILURE); /* Display command-line arguments given to core_pattern pipe program */ fprintf(fp, "argc=%d\n", argc); for (j = 0; j < argc; j++) fprintf(fp, "argc[%d]=<%s>\n", j, argv[j]); /* Count bytes in standard input (the core dump) */ tot = 0; while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0) tot += nread; fprintf(fp, "Total bytes in core dump: %d\n", tot); fclose(fp); exit(EXIT_SUCCESS); }