1 .\" Copyright (c) 2006, 2008 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH CORE 5 2021-03-22 "Linux" "Linux Programmer's Manual"
27 core \- core dump file
29 The default action of certain signals is to cause a process to terminate
31 .IR "core dump file" ,
32 a file containing an image of the process's memory at
33 the time of termination.
34 This image can be used in a debugger (e.g.,
36 to inspect the state of the program at the time that it terminated.
37 A list of the signals which cause a process to dump core can be found in
40 A process can set its soft
42 resource limit to place an upper limit on the size of the core dump file
43 that will be produced if it receives a "core dump" signal; see
47 There are various circumstances in which a core dump file is
50 The process does not have permission to write the core file.
51 (By default, the core file is called
57 is the ID of the process that dumped core,
58 and is created in the current working directory.
59 See below for details on naming.)
60 Writing the core file fails if the directory in which
61 it is to be created is not writable,
62 or if a file with the same name exists and
64 or is not a regular file
65 (e.g., it is a directory or a symbolic link).
67 A (writable, regular) file with the same name as would be used for the
68 core dump already exists, but there is more than one hard link to that
71 The filesystem where the core dump file would be created is full;
72 or has run out of inodes; or is mounted read-only;
73 or the user has reached their quota for the filesystem.
75 The directory in which the core dump file is to be created does
82 (file size) resource limits for the process are set to zero; see
84 and the documentation of the shell's
91 The binary being executed by the process does not have read
93 (This is a security measure to
94 ensure that an executable whose contents are not readable
95 does not produce a\(empossibly readable\(emcore dump containing
96 an image of the executable.)
98 The process is executing a set-user-ID (set-group-ID) program
99 that is owned by a user (group) other than the real user (group)
101 or the process is executing a program that has file capabilities (see
102 .BR capabilities (7)).
103 (However, see the description of the
106 operation, and the description of the
107 .I /proc/sys/fs/suid_dumpable
108 .\" FIXME . Perhaps relocate discussion of /proc/sys/fs/suid_dumpable
109 .\" and PR_SET_DUMPABLE to this page?
113 .I /proc/sys/kernel/core_pattern
115 .I /proc/sys/kernel/core_uses_pid
116 contains the value 0.
117 (These files are described below.)
119 .I /proc/sys/kernel/core_pattern
121 .I /proc/sys/kernel/core_uses_pid
122 contains the value 1,
123 core dump files will have names of the form
125 and such files are hidden unless one uses the
131 .\" commit 046d662f481830e652ac34cd112249adde16452a
132 The kernel was configured without the
137 a core dump may exclude part of the address space of the process if the
142 On systems that employ
146 framework, core dumps may instead be placed in a location determined by
148 See below for further details.
150 .SS Naming of core dump files
151 By default, a core dump file is named
154 .I /proc/sys/kernel/core_pattern
155 file (since Linux 2.6 and 2.4.21)
156 can be set to define a template that is used to name core dump files.
157 The template can contain % specifiers which are substituted
158 by the following values when a core file is created:
164 A single % character.
167 Core file size soft resource limit of crashing process (since Linux 2.6.24).
170 .\" Added in git commit 12a2b4b2241e318b4f6df31228e4272d2c2968a1
171 Dump mode\(emsame as value returned by
177 The process or thread's
179 value, which typically is the same as the executable filename
180 (without path prefix, and truncated to a maximum of 15 characters),
181 but may have been modified to be something different;
182 see the discussion of
185 .I /proc/[pid]/task/[tid]/comm
190 Pathname of executable,
191 with slashes (\(aq/\(aq) replaced by exclamation marks (\(aq!\(aq)
195 Numeric real GID of dumped process.
198 Hostname (same as \fInodename\fP returned by \fBuname\fP(2)).
201 TID of thread that triggered core dump,
202 as seen in the PID namespace in which the thread resides
203 .\" commit b03023ecbdb76c1dec86b41ed80b123c22783220
207 TID of thread that triggered core dump, as seen in the initial PID namespace
208 .\" commit b03023ecbdb76c1dec86b41ed80b123c22783220
212 PID of dumped process,
213 as seen in the PID namespace in which the process resides.
216 .\" Added in git commit 65aafb1e7484b7434a0c1d4c593191ebe5776a2f
217 PID of dumped process, as seen in the initial PID namespace
221 Number of signal causing dump.
224 Time of dump, expressed as seconds since the
225 Epoch, 1970-01-01 00:00:00 +0000 (UTC).
228 Numeric real UID of dumped process.
232 A single % at the end of the template is dropped from the
233 core filename, as is the combination of a % followed by any
234 character other than those listed above.
235 All other characters in the template become a literal
236 part of the core filename.
237 The template may include \(aq/\(aq characters, which are interpreted
238 as delimiters for directory names.
239 The maximum size of the resulting core filename is 128 bytes (64 bytes
240 in kernels before 2.6.19).
241 The default value in this file is "core".
242 For backward compatibility, if
243 .I /proc/sys/kernel/core_pattern
247 .I /proc/sys/kernel/core_uses_pid
249 is nonzero, then .PID will be appended to the core filename.
251 Paths are interpreted according to the settings that are active for the
253 That means the crashing process's mount namespace (see
254 .BR mount_namespaces (7)),
255 its current working directory (found via
257 and its root directory (see
260 Since version 2.4, Linux has also provided
261 a more primitive method of controlling
262 the name of the core dump file.
264 .I /proc/sys/kernel/core_uses_pid
265 file contains the value 0, then a core dump file is simply named
267 If this file contains a nonzero value, then the core dump file includes
268 the process ID in a name of the form
272 .\" 9520628e8ceb69fa9a4aee6b57f22675d9e1b709
274 .I /proc/sys/fs/suid_dumpable
275 is set to 2 ("suidsafe"), the pattern must be either an absolute pathname
276 (starting with a leading \(aq/\(aq character) or a pipe, as defined below.
277 .SS Piping core dumps to a program
278 Since kernel 2.6.19, Linux supports an alternate syntax for the
279 .I /proc/sys/kernel/core_pattern
281 If the first character of this file is a pipe symbol (\fB|\fP),
282 then the remainder of the line is interpreted as the command-line for
283 a user-space program (or script) that is to be executed.
286 .\" commit 315c69261dd3fa12dbc830d4fa00d1fad98d3b03
287 the pipe template is split on spaces into an argument list
289 the template parameters are expanded.
290 In earlier kernels, the template parameters are expanded first and
291 the resulting string is split on spaces into an argument list.
292 This means that in earlier kernels executable names added by the
296 template parameters could get split into multiple arguments.
297 So the core dump handler needs to put the executable names as the last
298 argument and ensure it joins all parts of the executable name using spaces.
299 Executable names with multiple spaces in them are not correctly represented
301 meaning that the core dump handler needs to use mechanisms to find
304 Instead of being written to a file, the core dump is given as
305 standard input to the program.
306 Note the following points:
308 The program must be specified using an absolute pathname (or a
309 pathname relative to the root directory, \fI/\fP),
310 and must immediately follow the '|' character.
312 The command-line arguments can include any of
313 the % specifiers listed above.
314 For example, to pass the PID of the process that is being dumped, specify
318 The process created to run the program runs as user and group
323 does not confer any exceptional security bypasses.
324 Namely, LSMs (e.g., SELinux) are still active and may prevent the handler
325 from accessing details about the crashed process via
328 The program pathname is interpreted with respect to the initial mount namespace
329 as it is always executed there.
330 It is not affected by the settings
331 (e.g., root directory, mount namespace, current working directory)
332 of the crashing process.
334 The process runs in the initial namespaces
335 (PID, mount, user, and so on)
336 and not in the namespaces of the crashing process.
337 One can utilize specifiers such as
341 directory and probe/enter the crashing process's namespaces if needed.
343 The process starts with its current working directory
344 as the root directory.
345 If desired, it is possible change to the working directory of
346 the dumping process by employing the value provided by the
348 specifier to change to the location of the dumping process via
349 .IR /proc/[pid]/cwd .
351 Command-line arguments can be supplied to the
352 program (since Linux 2.6.24),
353 delimited by white space (up to a total line length of 128 bytes).
357 limit is not enforced for core dumps that are piped to a program
360 .SS /proc/sys/kernel/core_pipe_limit
361 When collecting core dumps via a pipe to a user-space program,
362 it can be useful for the collecting program to gather data about
363 the crashing process from that process's
366 In order to do this safely,
367 the kernel must wait for the program collecting the core dump to exit,
368 so as not to remove the crashing process's
371 This in turn creates the
372 possibility that a misbehaving collecting program can block
373 the reaping of a crashed process by simply never exiting.
376 .\" commit a293980c2e261bd5b0d2a77340dd04f684caff58
378 .I /proc/sys/kernel/core_pipe_limit
379 can be used to defend against this possibility.
380 The value in this file defines how many concurrent crashing
381 processes may be piped to user-space programs in parallel.
382 If this value is exceeded, then those crashing processes above this value
383 are noted in the kernel log and their core dumps are skipped.
385 A value of 0 in this file is special.
386 It indicates that unlimited processes may be captured in parallel,
387 but that no waiting will take place (i.e., the collecting
388 program is not guaranteed access to
389 .IR /proc/<crashing\-PID> ).
390 The default value for this file is 0.
392 .SS Controlling which mappings are written to the core dump
393 Since kernel 2.6.23, the Linux-specific
394 .IR /proc/[pid]/coredump_filter
395 file can be used to control which memory segments are written to the
396 core dump file in the event that a core dump is performed for the
397 process with the corresponding process ID.
399 The value in the file is a bit mask of memory mapping types (see
401 If a bit is set in the mask, then memory mappings of the
402 corresponding type are dumped; otherwise they are not dumped.
403 The bits in this file have the following meanings:
409 Dump anonymous private mappings.
412 Dump anonymous shared mappings.
415 Dump file-backed private mappings.
418 Dump file-backed shared mappings.
419 .\" file-backed shared mappings of course also update the underlying
422 bit 4 (since Linux 2.6.24)
425 bit 5 (since Linux 2.6.28)
426 Dump private huge pages.
428 bit 6 (since Linux 2.6.28)
429 Dump shared huge pages.
431 bit 7 (since Linux 4.4)
432 .\" commit ab27a8d04b32b6ee8c30c14c4afd1058e8addc82
433 Dump private DAX pages.
435 bit 8 (since Linux 4.4)
436 .\" commit ab27a8d04b32b6ee8c30c14c4afd1058e8addc82
437 Dump shared DAX pages.
441 By default, the following bits are set: 0, 1, 4 (if the
442 .B CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS
443 kernel configuration option is enabled), and 5.
444 This default can be modified at boot time using the
448 The value of this file is displayed in hexadecimal.
449 (The default value is thus displayed as 33.)
451 Memory-mapped I/O pages such as frame buffer are never dumped, and
454 pages are always dumped, regardless of the
458 A child process created via
460 inherits its parent's
465 value is preserved across an
468 It can be useful to set
470 in the parent shell before running a program, for example:
474 .RB "$" " echo 0x7 > /proc/self/coredump_filter"
475 .RB "$" " ./some_program"
479 This file is provided only if the kernel was built with the
481 configuration option.
483 .SS Core dumps and systemd
487 framework, core dumps may be placed in a location determined by
493 feature that allows piping core dumps to a program.
494 One can verify this by checking whether core dumps are being piped to the
495 .BR systemd\-coredump (8)
500 $ \fBcat /proc/sys/kernel/core_pattern\fP
501 |/usr/lib/systemd/systemd\-coredump %P %u %g %s %t %c %e
505 In this case, core dumps will be placed in the location configured for
506 .BR systemd\-coredump (8),
509 compressed files in the directory
510 .IR /var/lib/systemd/coredump/ .
511 One can list the core dumps that have been recorded by
512 .BR systemd\-coredump (8)
517 $ \fBcoredumpctl list | tail \-5\fP
518 Wed 2017\-10\-11 22:25:30 CEST 2748 1000 1000 3 present /usr/bin/sleep
519 Thu 2017\-10\-12 06:29:10 CEST 2716 1000 1000 3 present /usr/bin/sleep
520 Thu 2017\-10\-12 06:30:50 CEST 2767 1000 1000 3 present /usr/bin/sleep
521 Thu 2017\-10\-12 06:37:40 CEST 2918 1000 1000 3 present /usr/bin/cat
522 Thu 2017\-10\-12 08:13:07 CEST 2955 1000 1000 3 present /usr/bin/cat
525 The information shown for each core dump includes the date and time
526 of the dump, the PID, UID, and GID of the dumping process,
527 the signal number that caused the core dump,
528 and the pathname of the executable that was being run by the dumped process.
531 allow a specified coredump file to be pulled from the
533 location into a specified file.
534 For example, to extract the core dump for PID 2955 shown above to a file named
536 in the current directory, one could use:
540 $ \fBcoredumpctl dump 2955 \-o core\fP
544 For more extensive details, see the
548 To (persistently) disable the
550 mechanism that archives core dumps, restoring to something more like
551 traditional Linux behavior, one can set an override for the
553 mechanism, using something like:
557 # \fBecho "kernel.core_pattern=core.%p" > \e\fP
558 \fB /etc/sysctl.d/50\-coredump.conf\fP
559 # \fB/lib/systemd/systemd\-sysctl\fP
563 It is also possible to temporarily (i.e., until the next reboot) change the
565 setting using a command such as the following
566 (which causes the names of core dump files to include the executable name
567 as well as the number of the signal which triggered the core dump):
571 # \fBsysctl \-w kernel.core_pattern="%e\-%s.core"\fP
579 command can be used to obtain a core dump of a running process.
581 In Linux versions up to and including 2.6.27,
582 .\" Changed with commit 6409324b385f3f63a03645b4422e3be67348d922
583 if a multithreaded process (or, more precisely, a process that
584 shares its memory with another process by being created with the
588 dumps core, then the process ID is always appended to the core filename,
589 unless the process ID was already included elsewhere in the
593 .IR /proc/sys/kernel/core_pattern .
594 (This is primarily useful when employing the obsolete
595 LinuxThreads implementation,
596 where each thread of a process has a different PID.)
597 .\" Always including the PID in the name of the core file made
598 .\" sense for LinuxThreads, where each thread had a unique PID,
599 .\" but doesn't seem to serve any purpose with NPTL, where all the
600 .\" threads in a process share the same PID (as POSIX.1 requires).
601 .\" Probably the behavior is maintained so that applications using
602 .\" LinuxThreads continue appending the PID (the kernel has no easy
603 .\" way of telling which threading implementation the user-space
604 .\" application is using). -- mtk, April 2006
606 The program below can be used to demonstrate the use of the
608 .I /proc/sys/kernel/core_pattern
610 The following shell session demonstrates the use of this program
611 (compiled to create an executable named
612 .IR core_pattern_pipe_test ):
616 .RB "$" " cc \-o core_pattern_pipe_test core_pattern_pipe_test.c"
619 .RB "#" " echo \(dq|$PWD/core_pattern_pipe_test %p \
620 UID=%u GID=%g sig=%s\(dq > \e"
621 .B " /proc/sys/kernel/core_pattern"
624 .BR "\(ha\e" " # type control\-backslash"
626 .RB "$" " cat core.info"
628 argc[0]=</home/mtk/core_pattern_pipe_test>
633 Total bytes in core dump: 282624
639 /* core_pattern_pipe_test.c */
642 #include <sys/stat.h>
649 #define BUF_SIZE 1024
652 main(int argc, char *argv[])
659 /* Change our current working directory to that of the
662 snprintf(cwd, PATH_MAX, "/proc/%s/cwd", argv[1]);
665 /* Write output to file "core.info" in that directory. */
667 fp = fopen("core.info", "w+");
671 /* Display command\-line arguments given to core_pattern
674 fprintf(fp, "argc=%d\en", argc);
675 for (int j = 0; j < argc; j++)
676 fprintf(fp, "argc[%d]=<%s>\en", j, argv[j]);
678 /* Count bytes in standard input (the core dump). */
681 while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0)
683 fprintf(fp, "Total bytes in core dump: %zd\en", tot);
701 .BR systemd\-coredump (8)