1 .\" Copyright (c) 2006, 2008 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .TH CORE 5 2021-03-22 "Linux" "Linux Programmer's Manual"
9 The default action of certain signals is to cause a process to terminate
11 .IR "core dump file" ,
12 a file containing an image of the process's memory at
13 the time of termination.
14 This image can be used in a debugger (e.g.,
16 to inspect the state of the program at the time that it terminated.
17 A list of the signals which cause a process to dump core can be found in
20 A process can set its soft
22 resource limit to place an upper limit on the size of the core dump file
23 that will be produced if it receives a "core dump" signal; see
27 There are various circumstances in which a core dump file is
30 The process does not have permission to write the core file.
31 (By default, the core file is called
37 is the ID of the process that dumped core,
38 and is created in the current working directory.
39 See below for details on naming.)
40 Writing the core file fails if the directory in which
41 it is to be created is not writable,
42 or if a file with the same name exists and
44 or is not a regular file
45 (e.g., it is a directory or a symbolic link).
47 A (writable, regular) file with the same name as would be used for the
48 core dump already exists, but there is more than one hard link to that
51 The filesystem where the core dump file would be created is full;
52 or has run out of inodes; or is mounted read-only;
53 or the user has reached their quota for the filesystem.
55 The directory in which the core dump file is to be created does
62 (file size) resource limits for the process are set to zero; see
64 and the documentation of the shell's
71 The binary being executed by the process does not have read
73 (This is a security measure to
74 ensure that an executable whose contents are not readable
75 does not produce a\(empossibly readable\(emcore dump containing
76 an image of the executable.)
78 The process is executing a set-user-ID (set-group-ID) program
79 that is owned by a user (group) other than the real user (group)
81 or the process is executing a program that has file capabilities (see
82 .BR capabilities (7)).
83 (However, see the description of the
86 operation, and the description of the
87 .I /proc/sys/fs/suid_dumpable
88 .\" FIXME . Perhaps relocate discussion of /proc/sys/fs/suid_dumpable
89 .\" and PR_SET_DUMPABLE to this page?
93 .I /proc/sys/kernel/core_pattern
95 .I /proc/sys/kernel/core_uses_pid
97 (These files are described below.)
99 .I /proc/sys/kernel/core_pattern
101 .I /proc/sys/kernel/core_uses_pid
102 contains the value 1,
103 core dump files will have names of the form
105 and such files are hidden unless one uses the
111 .\" commit 046d662f481830e652ac34cd112249adde16452a
112 The kernel was configured without the
117 a core dump may exclude part of the address space of the process if the
122 On systems that employ
126 framework, core dumps may instead be placed in a location determined by
128 See below for further details.
130 .SS Naming of core dump files
131 By default, a core dump file is named
134 .I /proc/sys/kernel/core_pattern
135 file (since Linux 2.6 and 2.4.21)
136 can be set to define a template that is used to name core dump files.
137 The template can contain % specifiers which are substituted
138 by the following values when a core file is created:
144 A single % character.
147 Core file size soft resource limit of crashing process (since Linux 2.6.24).
150 .\" Added in git commit 12a2b4b2241e318b4f6df31228e4272d2c2968a1
151 Dump mode\(emsame as value returned by
157 The process or thread's
159 value, which typically is the same as the executable filename
160 (without path prefix, and truncated to a maximum of 15 characters),
161 but may have been modified to be something different;
162 see the discussion of
165 .IR /proc/ pid /task/ tid /comm
170 Pathname of executable,
171 with slashes (\(aq/\(aq) replaced by exclamation marks (\(aq!\(aq)
175 Numeric real GID of dumped process.
178 Hostname (same as \fInodename\fP returned by \fBuname\fP(2)).
181 TID of thread that triggered core dump,
182 as seen in the PID namespace in which the thread resides
183 .\" commit b03023ecbdb76c1dec86b41ed80b123c22783220
187 TID of thread that triggered core dump, as seen in the initial PID namespace
188 .\" commit b03023ecbdb76c1dec86b41ed80b123c22783220
192 PID of dumped process,
193 as seen in the PID namespace in which the process resides.
196 .\" Added in git commit 65aafb1e7484b7434a0c1d4c593191ebe5776a2f
197 PID of dumped process, as seen in the initial PID namespace
201 Number of signal causing dump.
204 Time of dump, expressed as seconds since the
205 Epoch, 1970-01-01 00:00:00 +0000 (UTC).
208 Numeric real UID of dumped process.
212 A single % at the end of the template is dropped from the
213 core filename, as is the combination of a % followed by any
214 character other than those listed above.
215 All other characters in the template become a literal
216 part of the core filename.
217 The template may include \(aq/\(aq characters, which are interpreted
218 as delimiters for directory names.
219 The maximum size of the resulting core filename is 128 bytes (64 bytes
220 in kernels before 2.6.19).
221 The default value in this file is "core".
222 For backward compatibility, if
223 .I /proc/sys/kernel/core_pattern
227 .I /proc/sys/kernel/core_uses_pid
229 is nonzero, then .PID will be appended to the core filename.
231 Paths are interpreted according to the settings that are active for the
233 That means the crashing process's mount namespace (see
234 .BR mount_namespaces (7)),
235 its current working directory (found via
237 and its root directory (see
240 Since version 2.4, Linux has also provided
241 a more primitive method of controlling
242 the name of the core dump file.
244 .I /proc/sys/kernel/core_uses_pid
245 file contains the value 0, then a core dump file is simply named
247 If this file contains a nonzero value, then the core dump file includes
248 the process ID in a name of the form
252 .\" 9520628e8ceb69fa9a4aee6b57f22675d9e1b709
254 .I /proc/sys/fs/suid_dumpable
255 is set to 2 ("suidsafe"), the pattern must be either an absolute pathname
256 (starting with a leading \(aq/\(aq character) or a pipe, as defined below.
257 .SS Piping core dumps to a program
258 Since kernel 2.6.19, Linux supports an alternate syntax for the
259 .I /proc/sys/kernel/core_pattern
261 If the first character of this file is a pipe symbol (\fB|\fP),
262 then the remainder of the line is interpreted as the command-line for
263 a user-space program (or script) that is to be executed.
266 .\" commit 315c69261dd3fa12dbc830d4fa00d1fad98d3b03
267 the pipe template is split on spaces into an argument list
269 the template parameters are expanded.
270 In earlier kernels, the template parameters are expanded first and
271 the resulting string is split on spaces into an argument list.
272 This means that in earlier kernels executable names added by the
276 template parameters could get split into multiple arguments.
277 So the core dump handler needs to put the executable names as the last
278 argument and ensure it joins all parts of the executable name using spaces.
279 Executable names with multiple spaces in them are not correctly represented
281 meaning that the core dump handler needs to use mechanisms to find
284 Instead of being written to a file, the core dump is given as
285 standard input to the program.
286 Note the following points:
288 The program must be specified using an absolute pathname (or a
289 pathname relative to the root directory, \fI/\fP),
290 and must immediately follow the '|' character.
292 The command-line arguments can include any of
293 the % specifiers listed above.
294 For example, to pass the PID of the process that is being dumped, specify
298 The process created to run the program runs as user and group
303 does not confer any exceptional security bypasses.
304 Namely, LSMs (e.g., SELinux) are still active and may prevent the handler
305 from accessing details about the crashed process via
308 The program pathname is interpreted with respect to the initial mount namespace
309 as it is always executed there.
310 It is not affected by the settings
311 (e.g., root directory, mount namespace, current working directory)
312 of the crashing process.
314 The process runs in the initial namespaces
315 (PID, mount, user, and so on)
316 and not in the namespaces of the crashing process.
317 One can utilize specifiers such as
321 directory and probe/enter the crashing process's namespaces if needed.
323 The process starts with its current working directory
324 as the root directory.
325 If desired, it is possible change to the working directory of
326 the dumping process by employing the value provided by the
328 specifier to change to the location of the dumping process via
329 .IR /proc/ pid /cwd .
331 Command-line arguments can be supplied to the
332 program (since Linux 2.6.24),
333 delimited by white space (up to a total line length of 128 bytes).
337 limit is not enforced for core dumps that are piped to a program
340 .SS /proc/sys/kernel/core_pipe_limit
341 When collecting core dumps via a pipe to a user-space program,
342 it can be useful for the collecting program to gather data about
343 the crashing process from that process's
346 In order to do this safely,
347 the kernel must wait for the program collecting the core dump to exit,
348 so as not to remove the crashing process's
351 This in turn creates the
352 possibility that a misbehaving collecting program can block
353 the reaping of a crashed process by simply never exiting.
356 .\" commit a293980c2e261bd5b0d2a77340dd04f684caff58
358 .I /proc/sys/kernel/core_pipe_limit
359 can be used to defend against this possibility.
360 The value in this file defines how many concurrent crashing
361 processes may be piped to user-space programs in parallel.
362 If this value is exceeded, then those crashing processes above this value
363 are noted in the kernel log and their core dumps are skipped.
365 A value of 0 in this file is special.
366 It indicates that unlimited processes may be captured in parallel,
367 but that no waiting will take place (i.e., the collecting
368 program is not guaranteed access to
369 .IR /proc/<crashing\-PID> ).
370 The default value for this file is 0.
372 .SS Controlling which mappings are written to the core dump
373 Since kernel 2.6.23, the Linux-specific
374 .IR /proc/ pid /coredump_filter
375 file can be used to control which memory segments are written to the
376 core dump file in the event that a core dump is performed for the
377 process with the corresponding process ID.
379 The value in the file is a bit mask of memory mapping types (see
381 If a bit is set in the mask, then memory mappings of the
382 corresponding type are dumped; otherwise they are not dumped.
383 The bits in this file have the following meanings:
389 Dump anonymous private mappings.
392 Dump anonymous shared mappings.
395 Dump file-backed private mappings.
398 Dump file-backed shared mappings.
399 .\" file-backed shared mappings of course also update the underlying
402 bit 4 (since Linux 2.6.24)
405 bit 5 (since Linux 2.6.28)
406 Dump private huge pages.
408 bit 6 (since Linux 2.6.28)
409 Dump shared huge pages.
411 bit 7 (since Linux 4.4)
412 .\" commit ab27a8d04b32b6ee8c30c14c4afd1058e8addc82
413 Dump private DAX pages.
415 bit 8 (since Linux 4.4)
416 .\" commit ab27a8d04b32b6ee8c30c14c4afd1058e8addc82
417 Dump shared DAX pages.
421 By default, the following bits are set: 0, 1, 4 (if the
422 .B CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS
423 kernel configuration option is enabled), and 5.
424 This default can be modified at boot time using the
428 The value of this file is displayed in hexadecimal.
429 (The default value is thus displayed as 33.)
431 Memory-mapped I/O pages such as frame buffer are never dumped, and
434 pages are always dumped, regardless of the
438 A child process created via
440 inherits its parent's
445 value is preserved across an
448 It can be useful to set
450 in the parent shell before running a program, for example:
454 .RB "$" " echo 0x7 > /proc/self/coredump_filter"
455 .RB "$" " ./some_program"
459 This file is provided only if the kernel was built with the
461 configuration option.
463 .SS Core dumps and systemd
467 framework, core dumps may be placed in a location determined by
473 feature that allows piping core dumps to a program.
474 One can verify this by checking whether core dumps are being piped to the
475 .BR systemd\-coredump (8)
480 $ \fBcat /proc/sys/kernel/core_pattern\fP
481 |/usr/lib/systemd/systemd\-coredump %P %u %g %s %t %c %e
485 In this case, core dumps will be placed in the location configured for
486 .BR systemd\-coredump (8),
489 compressed files in the directory
490 .IR /var/lib/systemd/coredump/ .
491 One can list the core dumps that have been recorded by
492 .BR systemd\-coredump (8)
497 $ \fBcoredumpctl list | tail \-5\fP
498 Wed 2017\-10\-11 22:25:30 CEST 2748 1000 1000 3 present /usr/bin/sleep
499 Thu 2017\-10\-12 06:29:10 CEST 2716 1000 1000 3 present /usr/bin/sleep
500 Thu 2017\-10\-12 06:30:50 CEST 2767 1000 1000 3 present /usr/bin/sleep
501 Thu 2017\-10\-12 06:37:40 CEST 2918 1000 1000 3 present /usr/bin/cat
502 Thu 2017\-10\-12 08:13:07 CEST 2955 1000 1000 3 present /usr/bin/cat
505 The information shown for each core dump includes the date and time
506 of the dump, the PID, UID, and GID of the dumping process,
507 the signal number that caused the core dump,
508 and the pathname of the executable that was being run by the dumped process.
511 allow a specified coredump file to be pulled from the
513 location into a specified file.
514 For example, to extract the core dump for PID 2955 shown above to a file named
516 in the current directory, one could use:
520 $ \fBcoredumpctl dump 2955 \-o core\fP
524 For more extensive details, see the
528 To (persistently) disable the
530 mechanism that archives core dumps, restoring to something more like
531 traditional Linux behavior, one can set an override for the
533 mechanism, using something like:
537 # \fBecho "kernel.core_pattern=core.%p" > \e\fP
538 \fB /etc/sysctl.d/50\-coredump.conf\fP
539 # \fB/lib/systemd/systemd\-sysctl\fP
543 It is also possible to temporarily (i.e., until the next reboot) change the
545 setting using a command such as the following
546 (which causes the names of core dump files to include the executable name
547 as well as the number of the signal which triggered the core dump):
551 # \fBsysctl \-w kernel.core_pattern="%e\-%s.core"\fP
559 command can be used to obtain a core dump of a running process.
561 In Linux versions up to and including 2.6.27,
562 .\" Changed with commit 6409324b385f3f63a03645b4422e3be67348d922
563 if a multithreaded process (or, more precisely, a process that
564 shares its memory with another process by being created with the
568 dumps core, then the process ID is always appended to the core filename,
569 unless the process ID was already included elsewhere in the
573 .IR /proc/sys/kernel/core_pattern .
574 (This is primarily useful when employing the obsolete
575 LinuxThreads implementation,
576 where each thread of a process has a different PID.)
577 .\" Always including the PID in the name of the core file made
578 .\" sense for LinuxThreads, where each thread had a unique PID,
579 .\" but doesn't seem to serve any purpose with NPTL, where all the
580 .\" threads in a process share the same PID (as POSIX.1 requires).
581 .\" Probably the behavior is maintained so that applications using
582 .\" LinuxThreads continue appending the PID (the kernel has no easy
583 .\" way of telling which threading implementation the user-space
584 .\" application is using). -- mtk, April 2006
586 The program below can be used to demonstrate the use of the
588 .I /proc/sys/kernel/core_pattern
590 The following shell session demonstrates the use of this program
591 (compiled to create an executable named
592 .IR core_pattern_pipe_test ):
596 .RB "$" " cc \-o core_pattern_pipe_test core_pattern_pipe_test.c"
599 .RB "#" " echo \(dq|$PWD/core_pattern_pipe_test %p \
600 UID=%u GID=%g sig=%s\(dq > \e"
601 .B " /proc/sys/kernel/core_pattern"
604 .BR "\(ha\e" " # type control\-backslash"
606 .RB "$" " cat core.info"
608 argc[0]=</home/mtk/core_pattern_pipe_test>
613 Total bytes in core dump: 282624
619 /* core_pattern_pipe_test.c */
622 #include <sys/stat.h>
629 #define BUF_SIZE 1024
632 main(int argc, char *argv[])
639 /* Change our current working directory to that of the
642 snprintf(cwd, PATH_MAX, "/proc/%s/cwd", argv[1]);
645 /* Write output to file "core.info" in that directory. */
647 fp = fopen("core.info", "w+");
651 /* Display command\-line arguments given to core_pattern
654 fprintf(fp, "argc=%d\en", argc);
655 for (int j = 0; j < argc; j++)
656 fprintf(fp, "argc[%d]=<%s>\en", j, argv[j]);
658 /* Count bytes in standard input (the core dump). */
661 while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0)
663 fprintf(fp, "Total bytes in core dump: %zd\en", tot);
681 .BR systemd\-coredump (8)