core(5) File Formats Manual core(5) core - The default action of certain signals is to cause a process to terminate and produce a core dump file, a file containing an image of the process's memory at the time of termination. This image can be used in a debugger (e.g., gdb(1)) to inspect the state of the program at the time that it terminated. A list of the signals which cause a process to dump core can be found in signal(7). RLIMIT_CORE , , " "; getrlimit(2). , : o ( core core.pid, pid -- ID , . ). , , , , (, ). o (, ) , , . o , , , , , . o , , . o The RLIMIT_CORE (core file size) or RLIMIT_FSIZE (file size) resource limits for the process are set to zero; see getrlimit(2) and the documentation of the shell's ulimit command (limit in csh(1)). However, RLIMIT_CORE will be ignored if the system is configured to pipe core dumps to a program. o The binary being executed by the process does not have read permission enabled. (This is a security measure to ensure that an executable whose contents are not readable does not produce a--possibly readable--core dump containing an image of the executable.) o set-user-ID (set-group-ID), () ID () , ( capabilities(7)). prctl(2) PR_SET_DUMPABLE, /proc/sys/fs/suid_dumpable proc(5). o /proc/sys/kernel/core_pattern /proc/sys/kernel/core_uses_pid 0 ( ). , /proc/sys/kernel/core_pattern /proc/sys/kernel/core_uses_pid 1, .pid, ls(1) -a. o ( Linux 3.7) CONFIG_COREDUMP. , , madvise(2) MADV_DONTDUMP. , systemd(1) init, , systemd(1). . , core, /proc/sys/kernel/core_pattern ( Linux 2.6 2.4.21) , . %, : %% %. %c ( Linux 2.6.24). %d Dump mode--same as value returned by prctl(2) PR_GET_DUMPABLE (since Linux 3.7). %e The process or thread's comm value, which typically is the same as the executable filename (without path prefix, and truncated to a maximum of 15 characters), but may have been modified to be something different; see the discussion of /proc/pid/comm and /proc/pid/task/tid/comm in proc(5). %E Pathname of executable, with slashes ('/') replaced by exclamation marks ('!') (since Linux 3.0). %g Numeric real GID of dumped process. %h ( nodename, uname(2)). %i TID , - , PID, ( Linux 3.18). %I TID , - , PID ( Linux 3.18). %p PID , , PID, . %P initial PID , , PID, ( Linux 3.12). %s , . %t , , 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 '/' characters, which are interpreted as delimiters for directory names. The maximum size of the resulting core filename is 128 bytes (64 bytes before Linux 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. . ( mount_namespaces(7)), ( getcwd(2)) ( chroot(2)). Since Linux 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 '/' character) or a pipe, as defined below. Since Linux 2.6.19, Linux supports an alternate syntax for the /proc/sys/kernel/core_pattern file. If the first character of this file is a pipe symbol (|), then the remainder of the line is interpreted as the command-line for a user-space program (or script) that is to be executed. Since Linux 5.3.0, the pipe template is split on spaces into an argument list before the template parameters are expanded. In earlier kernels, the template parameters are expanded first and the resulting string is split on spaces into an argument list. This means that in earlier kernels executable names added by the %e and %E template parameters could get split into multiple arguments. So the core dump handler needs to put the executable names as the last argument and ensure it joins all parts of the executable name using spaces. Executable names with multiple spaces in them are not correctly represented in earlier kernels, meaning that the core dump handler needs to use mechanisms to find the executable name. Instead of being written to a file, the core dump is given as standard input to the program. Note the following points: o ( , /), <<|>>. o %, . , PID , , %p. o root. o root . , LSM (, SELinux) /proc/pid. o , . (, , , ) . o (PID, , . .), . , %P, /proc/pid , , / . o , . , %P /proc/pid/cwd. o ( Linux 2.6.24), ( 128 ). o RLIMIT_CORE , . /proc/sys/kernel/core_pipe_limit /proc/pid. , /proc/pid. , , , . Linux 2.6.32, /proc/sys/kernel/core_pipe_limit. , . , , . 0 . , , (. ., /proc/). 0. , Since Linux 2.6.23, the Linux-specific /proc/pid/coredump_filter file can be used to control which memory segments are written to the core dump file in the event that a core dump is performed for the process with the corresponding process ID. (. mmap(2)). , ; . : 0 . 1 . 2 (file-backed). 3 (file-backed). 4 ( Linux 2.6.24) ELF. 5 ( Linux 2.6.28) . 6 ( Linux 2.6.28) . 7 ( Linux 4.4) DAX. 8 ( Linux 4.4) DAX. , : 0, 1, 4 ( CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS) 5. coredump_filter. ( 33). -, , -, , DSO (vdso(7)) , coredump_filter. , fork(2), coredump_filter ; coredump_filter execve(2). coredump_filter , : $ echo 0x7 > /proc/self/coredump_filter $ ./-_ , CONFIG_ELF_CORE. systemd systemd(1) init , systemd(1). systemd(1) core_pattern, . , systemd-coredump(8): $ cat /proc/sys/kernel/core_pattern |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %e systemd-coredump(8), lz4(1) /var/lib/systemd/coredump/. , systemd-coredump(8), coredumpctl(1): $ coredumpctl list | tail -5 Wed 2017-10-11 22:25:30 CEST 2748 1000 1000 3 present /usr/bin/sleep Thu 2017-10-12 06:29:10 CEST 2716 1000 1000 3 present /usr/bin/sleep Thu 2017-10-12 06:30:50 CEST 2767 1000 1000 3 present /usr/bin/sleep Thu 2017-10-12 06:37:40 CEST 2918 1000 1000 3 present /usr/bin/cat Thu 2017-10-12 08:13:07 CEST 2955 1000 1000 3 present /usr/bin/cat , , PID, UID GID , , , , . coredumpctl(1) coredump, systemd(1), . , PID 2955, , core , : $ coredumpctl dump 2955 -o core coredumpctl(1). To (persistently) disable the systemd(1) mechanism that archives core dumps, restoring to something more like traditional Linux behavior, one can set an override for the systemd(1) mechanism, using something like: # echo "kernel.core_pattern=core.%p" > \ /etc/sysctl.d/50-coredump.conf # /lib/systemd/systemd-sysctl It is also possible to temporarily (i.e., until the next reboot) change the core_pattern setting using a command such as the following (which causes the names of core dump files to include the executable name as well as the number of the signal which triggered the core dump): # sysctl -w kernel.core_pattern="%e-%s.core" gdb(1) gcore . Linux 26.27 , (, , , , CLONE_VM clone(2)) , ID , ID %p /proc/sys/kernel/core_pattern (, , LinuxThreads, PID). /proc/sys/kernel/core_pattern. ( core_pattern_pipe_test): $ cc -o core_pattern_pipe_test core_pattern_pipe_test.c $ su Password: # echo "|$PWD/core_pattern_pipe_test %p UID=%u GID=%g sig=%s" > \ /proc/sys/kernel/core_pattern # exit $ sleep 100 ^\ # type control-backslash Quit (core dumped) $ cat core.info argc=5 argc[0]= argc[1]=<20575> argc[2]= argc[3]= argc[4]= Total bytes in core dump: 282624 /* core_pattern_pipe_test.c */ #define _GNU_SOURCE #include #include #include #include #include #include #define BUF_SIZE 1024 int main(int argc, char *argv[]) { ssize_t nread, tot; 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 (size_t j = 0; j < argc; j++) fprintf(fp, "argc[%zu]=<%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: %zd\n", tot); fclose(fp); exit(EXIT_SUCCESS); } . bash(1), coredumpctl(1), gdb(1), getrlimit(2), mmap(2), prctl(2), sigaction(2), elf(5), proc(5), pthreads(7), signal(7), systemd-coredump(8) Azamat Hackimov , Dmitriy S. Seregin , Dmitry Bolkhovskikh , Katrin Kutepova , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . core(5)