Debian Codegraph @

upstream/debian-unstable/man5/core.5

raw
1 .\" Copyright 2006-2008, Michael Kerrisk <[email protected]>
2 .\" Copyright, the authors of the Linux man-pages project
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH core 5 2026-03-16 "Linux man-pages 6.18"
7 .SH NAME
8 core \- core dump file
9 .SH DESCRIPTION
10 The default action of certain signals is to cause a process to terminate
11 and produce a
12 .IR "core dump file" ,
13 a file containing an image of the process's memory at
14 the time of termination.
15 This image can be used in a debugger (e.g.,
16 .BR gdb (1))
17 to inspect the state of the program at the time that it terminated.
18 A list of the signals which cause a process to dump core can be found in
19 .BR signal (7).
20 .P
21 A process can set its soft
22 .B RLIMIT_CORE
23 resource limit to place
24 an upper limit on the size of the core dump file
25 that will be produced if it receives a "core dump" signal;
26 see
27 .BR getrlimit (2)
28 for details.
29 .P
30 There are various circumstances in which a core dump file is
31 not produced:
32 .IP \[bu] 3
33 The process does not have permission to write the core file.
34 (By default, the core file is called
35 .I core
36 or
37 .IR core.pid ,
38 where
39 .I pid
40 is the ID of the process that dumped core,
41 and is created in the current working directory.
42 See below for details on naming.)
43 Writing the core file fails if the directory in which
44 it is to be created is not writable,
45 or if a file with the same name exists and
46 is not writable
47 or is not a regular file
48 (e.g., it is a directory or a symbolic link).
49 .IP \[bu]
50 A (writable, regular) file with the same name as would be used for the
51 core dump already exists, but there is more than one hard link to that
52 file.
53 .IP \[bu]
54 The filesystem where the core dump file would be created is full;
55 or has run out of inodes;
56 or is mounted read-only;
57 or the user has reached their quota for the filesystem.
58 .IP \[bu]
59 The directory in which the core dump file is to be created does
60 not exist.
61 .IP \[bu]
62 The
63 .B RLIMIT_CORE
64 (core file size) or
65 .B RLIMIT_FSIZE
66 (file size) resource limits for the process are set to zero;
67 see
68 .BR getrlimit (2)
69 and the documentation of the shell's
70 .I ulimit
71 command
72 .RI ( limit
73 in
74 .BR csh (1)).
75 However,
76 .B RLIMIT_CORE
77 will be ignored if the system is configured to pipe core dumps to a program.
78 .IP \[bu]
79 The binary being executed by the process does not have read
80 permission enabled.
81 (This is a security measure to
82 ensure that an executable whose contents are not readable
83 does not produce a\[em]possibly readable\[em]core dump containing
84 an image of the executable.)
85 .IP \[bu]
86 The process is executing a set-user-ID (set-group-ID) program
87 that is owned by a user (group) other than the real user (group)
88 ID of the process,
89 or the process is executing a program that has file capabilities (see
90 .BR capabilities (7)).
91 (However, see the description of the
92 .BR prctl (2)
93 .B PR_SET_DUMPABLE
94 operation, and the description of the
95 .I /proc/sys/fs/suid_dumpable
96 .\" FIXME . Perhaps relocate discussion of /proc/sys/fs/suid_dumpable
97 .\" and PR_SET_DUMPABLE to this page?
98 file in
99 .BR proc (5).)
100 .IP \[bu]
101 .I /proc/sys/kernel/core_pattern
102 is empty and
103 .I /proc/sys/kernel/core_uses_pid
104 contains the value 0.
105 (These files are described below.)
106 Note that if
107 .I /proc/sys/kernel/core_pattern
108 is empty and
109 .I /proc/sys/kernel/core_uses_pid
110 contains the value 1,
111 core dump files will have names of the form
112 .IR .pid ,
113 and such files are hidden unless one uses the
114 .BR ls (1)
115 .I \-a
116 option.
117 .IP \[bu]
118 (Since Linux 3.7)
119 .\" commit 046d662f481830e652ac34cd112249adde16452a
120 The kernel was configured without the
121 .B CONFIG_COREDUMP
122 option.
123 .P
124 In addition,
125 a core dump may exclude part of the address space of the process if the
126 .BR madvise (2)
127 .B MADV_DONTDUMP
128 flag was employed.
129 .P
130 On systems that employ
131 .BR systemd (1)
132 as the
133 .I init
134 framework, core dumps may instead be placed in a location determined by
135 .BR systemd (1).
136 See below for further details.
137 .\"
138 .SS Naming of core dump files
139 By default, a core dump file is named
140 .IR core ,
141 but the
142 .I /proc/sys/kernel/core_pattern
143 file (since Linux 2.6 and 2.4.21)
144 can be set to define a template that is used to name core dump files.
145 The template can contain % specifiers which are substituted
146 by the following values when a core file is created:
147 .P
148 .RS 4
149 .PD 0
150 .TP 4
151 %%
152 A single % character.
153 .TP
154 %c
155 Core file size soft resource limit of crashing process (since Linux 2.6.24).
156 .TP
157 %C
158 CPU the task ran on
159 .\" commit 8603b6f58637ce196d68f7749633ea81af196d66
160 (since Linux 6.2).
161 .TP
162 %d
163 .\" Added in git commit 12a2b4b2241e318b4f6df31228e4272d2c2968a1
164 Dump mode\[em]same as value returned by
165 .BR prctl (2)
166 .B PR_GET_DUMPABLE
167 (since Linux 3.7).
168 .TP
169 %e
170 The process or thread's
171 .I comm
172 value, which typically is the same as the executable filename
173 (without path prefix, and truncated to a maximum of 15 characters),
174 but may have been modified to be something different;
175 see the discussion of
176 .IR /proc/ pid /comm
177 and
178 .IR /proc/ pid /task/ tid /comm
179 in
180 .BR proc (5).
181 .TP
182 %E
183 Pathname of executable,
184 with slashes (\[aq]/\[aq]) replaced by exclamation marks (\[aq]!\[aq])
185 (since Linux 3.0).
186 .TP
187 %f
188 Actual filename of executable, which may differ from %e
189 .\" commit f38c85f1ba6902e4e2e2bf1b84edf065a904cdeb
190 (since Linux 5.9).
191 .TP
192 %F
193 PIDFD of dumped process
194 .\" commit b5325b2a270fcaf7b2a9a0f23d422ca8a5a8bdea
195 (since Linux 6.16).
196 .TP
197 %g
198 Numeric real GID of dumped process.
199 .TP
200 %h
201 Hostname (same as
202 .I nodename
203 returned by
204 .BR uname (2)).
205 .TP
206 %i
207 TID of thread that triggered core dump,
208 as seen in the PID namespace in which the thread resides
209 .\" commit b03023ecbdb76c1dec86b41ed80b123c22783220
210 (since Linux 3.18).
211 .TP
212 %I
213 TID of thread that triggered core dump, as seen in the initial PID namespace
214 .\" commit b03023ecbdb76c1dec86b41ed80b123c22783220
215 (since Linux 3.18).
216 .TP
217 %p
218 PID of dumped process,
219 as seen in the PID namespace in which the process resides.
220 .TP
221 %P
222 .\" Added in git commit 65aafb1e7484b7434a0c1d4c593191ebe5776a2f
223 PID of dumped process, as seen in the initial PID namespace
224 (since Linux 3.12).
225 .TP
226 %s
227 Number of signal causing dump.
228 .TP
229 %t
230 Time of dump, expressed as seconds since the
231 Epoch, 1970-01-01 00:00:00 +0000 (UTC).
232 .TP
233 %u
234 Numeric real UID of dumped process.
235 .PD
236 .RE
237 .P
238 A single % at the end of the template is dropped from the
239 core filename, as is the combination of a % followed by any
240 character other than those listed above.
241 All other characters in the template become a literal
242 part of the core filename.
243 The template may include \[aq]/\[aq] characters, which are interpreted
244 as delimiters for directory names.
245 The maximum size of the resulting core filename is 128 bytes (64 bytes
246 before Linux 2.6.19).
247 The default value in this file is "core".
248 For backward compatibility, if
249 .I /proc/sys/kernel/core_pattern
250 does not include
251 .I %p
252 and
253 .I /proc/sys/kernel/core_uses_pid
254 (see below)
255 is nonzero, then .PID will be appended to the core filename.
256 .P
257 Paths are interpreted according to the settings that are active for the
258 crashing process.
259 That means the crashing process's mount namespace (see
260 .BR mount_namespaces (7)),
261 its current working directory (found via
262 .BR getcwd (2)),
263 and its root directory (see
264 .BR chroot (2)).
265 .P
266 Since Linux 2.4, Linux has also provided
267 a more primitive method of controlling
268 the name of the core dump file.
269 If the
270 .I /proc/sys/kernel/core_uses_pid
271 file contains the value 0, then a core dump file is simply named
272 .IR core .
273 If this file contains a nonzero value, then the core dump file includes
274 the process ID in a name of the form
275 .IR core.PID .
276 .P
277 Since Linux 3.6,
278 .\" 9520628e8ceb69fa9a4aee6b57f22675d9e1b709
279 if
280 .I /proc/sys/fs/suid_dumpable
281 is set to 2 ("suidsafe"), the pattern must be either an absolute pathname
282 (starting with a leading \[aq]/\[aq] character) or a pipe, as defined below.
283 .SS Piping core dumps to a program
284 Since Linux 2.6.19, Linux supports an alternate syntax for the
285 .I /proc/sys/kernel/core_pattern
286 file.
287 If the first character of this file is a pipe symbol
288 .RI ( | ),
289 then the remainder of the line is interpreted as the command-line for
290 a user-space program (or script) that is to be executed.
291 .P
292 Since Linux 5.3.0,
293 .\" commit 315c69261dd3fa12dbc830d4fa00d1fad98d3b03
294 the pipe template is split on spaces into an argument list
295 .I before
296 the template parameters are expanded.
297 In earlier kernels, the template parameters are expanded first and
298 the resulting string is split on spaces into an argument list.
299 This means that in earlier kernels executable names added by the
300 .I %e
301 and
302 .I %E
303 template parameters could get split into multiple arguments.
304 So the core dump handler needs to put the executable names as the last
305 argument and ensure it joins all parts of the executable name using spaces.
306 Executable names with multiple spaces in them are not correctly represented
307 in earlier kernels,
308 meaning that the core dump handler needs to use mechanisms to find
309 the executable name.
310 .P
311 Instead of being written to a file, the core dump is given as
312 standard input to the program.
313 Note the following points:
314 .IP \[bu] 3
315 The program must be specified using an absolute pathname (or a
316 pathname relative to the root directory,
317 .IR / ),
318 and must immediately follow the '|' character.
319 .IP \[bu]
320 The command-line arguments can include any of
321 the % specifiers listed above.
322 For example, to pass the PID of the process that is being dumped, specify
323 .I %p
324 in an argument.
325 .IP \[bu]
326 The process created to run the program runs as user and group
327 .IR root .
328 .IP \[bu]
329 Running as
330 .I root
331 does not confer any exceptional security bypasses.
332 Namely, LSMs (e.g., SELinux) are still active and may prevent the handler
333 from accessing details about the crashed process via
334 .IR /proc/ pid.
335 .IP \[bu]
336 The program pathname is interpreted with respect to the initial mount namespace
337 as it is always executed there.
338 It is not affected by the settings
339 (e.g., root directory, mount namespace, current working directory)
340 of the crashing process.
341 .IP \[bu]
342 The process runs in the initial namespaces
343 (PID, mount, user, and so on)
344 and not in the namespaces of the crashing process.
345 One can utilize specifiers such as
346 .I %P
347 to find the right
348 .IR /proc/ pid
349 directory and probe/enter the crashing process's namespaces if needed.
350 .IP \[bu]
351 The process starts with its current working directory
352 as the root directory.
353 If desired, it is possible change to the working directory of
354 the dumping process by employing the value provided by the
355 .I %P
356 specifier to change to the location of the dumping process via
357 .IR /proc/ pid /cwd .
358 .IP \[bu]
359 Command-line arguments can be supplied to the
360 program (since Linux 2.6.24),
361 delimited by white space (up to a total line length of 128 bytes).
362 .IP \[bu]
363 The
364 .B RLIMIT_CORE
365 limit is not enforced for core dumps that are piped to a program
366 via this mechanism.
367 .\"
368 .SS /proc/sys/kernel/core_pipe_limit
369 When collecting core dumps via a pipe to a user-space program,
370 it can be useful for the collecting program to gather data about
371 the crashing process from that process's
372 .IR /proc/ pid
373 directory.
374 In order to do this safely,
375 the kernel must wait for the program collecting the core dump to exit,
376 so as not to remove the crashing process's
377 .IR /proc/ pid
378 files prematurely.
379 This in turn creates the
380 possibility that a misbehaving collecting program can block
381 the reaping of a crashed process by simply never exiting.
382 .P
383 Since Linux 2.6.32,
384 .\" commit a293980c2e261bd5b0d2a77340dd04f684caff58
385 the
386 .I /proc/sys/kernel/core_pipe_limit
387 can be used to defend against this possibility.
388 The value in this file defines how many concurrent crashing
389 processes may be piped to user-space programs in parallel.
390 If this value is exceeded, then those crashing processes above this value
391 are noted in the kernel log and their core dumps are skipped.
392 .P
393 A value of 0 in this file is special.
394 It indicates that unlimited processes may be captured in parallel,
395 but that no waiting will take place (i.e., the collecting
396 program is not guaranteed access to
397 .IR /proc/<crashing\-PID> ).
398 The default value for this file is 0.
399 .\"
400 .SS Controlling which mappings are written to the core dump
401 Since Linux 2.6.23, the Linux-specific
402 .IR /proc/ pid /coredump_filter
403 file can be used to control which memory segments are written to the
404 core dump file in the event that a core dump is performed for the
405 process with the corresponding process ID.
406 .P
407 The value in the file is a bit mask of memory mapping types (see
408 .BR mmap (2)).
409 If a bit is set in the mask,
410 then memory mappings of the corresponding type are dumped;
411 otherwise,
412 they are not dumped.
413 The bits in this file have the following meanings:
414 .P
415 .PD 0
416 .RS 4
417 .TP
418 bit 0
419 Dump anonymous private mappings.
420 .TP
421 bit 1
422 Dump anonymous shared mappings.
423 .TP
424 bit 2
425 Dump file-backed private mappings.
426 .TP
427 bit 3
428 Dump file-backed shared mappings.
429 .\" file-backed shared mappings of course also update the underlying
430 .\" mapped file.
431 .TP
432 bit 4 (since Linux 2.6.24)
433 Dump ELF headers.
434 .TP
435 bit 5 (since Linux 2.6.28)
436 Dump private huge pages.
437 .TP
438 bit 6 (since Linux 2.6.28)
439 Dump shared huge pages.
440 .TP
441 bit 7 (since Linux 4.4)
442 .\" commit ab27a8d04b32b6ee8c30c14c4afd1058e8addc82
443 Dump private DAX pages.
444 .TP
445 bit 8 (since Linux 4.4)
446 .\" commit ab27a8d04b32b6ee8c30c14c4afd1058e8addc82
447 Dump shared DAX pages.
448 .RE
449 .PD
450 .P
451 By default, the following bits are set: 0, 1, 4 (if the
452 .B CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS
453 kernel configuration option is enabled), and 5.
454 This default can be modified at boot time using the
455 .I coredump_filter
456 boot option.
457 .P
458 The value of this file is displayed in hexadecimal.
459 (The default value is thus displayed as 33.)
460 .P
461 Memory-mapped I/O pages such as frame buffer are never dumped, and
462 virtual DSO
463 .RB ( vdso (7))
464 pages are always dumped, regardless of the
465 .I coredump_filter
466 value.
467 .P
468 A child process created via
469 .BR fork (2)
470 inherits its parent's
471 .I coredump_filter
472 value;
473 the
474 .I coredump_filter
475 value is preserved across an
476 .BR execve (2).
477 .P
478 It can be useful to set
479 .I coredump_filter
480 in the parent shell before running a program, for example:
481 .P
482 .in +4n
483 .EX
484 .RB "$" " echo 0x7 > /proc/self/coredump_filter"
485 .RB "$" " ./some_program"
486 .EE
487 .in
488 .P
489 This file is provided only if the kernel was built with the
490 .B CONFIG_ELF_CORE
491 configuration option.
492 .\"
493 .SS Core dumps and systemd
494 On systems using the
495 .BR systemd (1)
496 .I init
497 framework, core dumps may be placed in a location determined by
498 .BR systemd (1).
499 To do this,
500 .BR systemd (1)
501 employs the
502 .I core_pattern
503 feature that allows piping core dumps to a program.
504 One can verify this by checking whether core dumps are being piped to the
505 .BR systemd\-coredump (8)
506 program:
507 .P
508 .in +4n
509 .EX
510 .RB $ " cat /proc/sys/kernel/core_pattern" ;
511 |/usr/lib/systemd/systemd\-coredump %P %u %g %s %t %c %e
512 .EE
513 .in
514 .P
515 In this case, core dumps will be placed in the location configured for
516 .BR systemd\-coredump (8),
517 typically as
518 .BR lz4 (1)
519 compressed files in the directory
520 .IR /var/lib/systemd/coredump/ .
521 One can list the core dumps that have been recorded by
522 .BR systemd\-coredump (8)
523 using
524 .BR coredumpctl (1):
525 .P
526 .EX
527 .RB $ " coredumpctl list | tail \-5" ;
528 Wed 2017\-10\-11 22:25:30 CEST 2748 1000 1000 3 present /usr/bin/sleep
529 Thu 2017\-10\-12 06:29:10 CEST 2716 1000 1000 3 present /usr/bin/sleep
530 Thu 2017\-10\-12 06:30:50 CEST 2767 1000 1000 3 present /usr/bin/sleep
531 Thu 2017\-10\-12 06:37:40 CEST 2918 1000 1000 3 present /usr/bin/cat
532 Thu 2017\-10\-12 08:13:07 CEST 2955 1000 1000 3 present /usr/bin/cat
533 .EE
534 .P
535 The information shown for each core dump includes the date and time
536 of the dump, the PID, UID, and GID of the dumping process,
537 the signal number that caused the core dump,
538 and the pathname of the executable that was being run by the dumped process.
539 Various options to
540 .BR coredumpctl (1)
541 allow a specified coredump file to be pulled from the
542 .BR systemd (1)
543 location into a specified file.
544 For example, to extract the core dump for PID 2955 shown above to a file named
545 .I core
546 in the current directory, one could use:
547 .P
548 .in +4n
549 .EX
550 .RB $ " coredumpctl dump 2955 \-o core" ;
551 .EE
552 .in
553 .P
554 For more extensive details, see the
555 .BR coredumpctl (1)
556 manual page.
557 .P
558 To (persistently) disable the
559 .BR systemd (1)
560 mechanism that archives core dumps, restoring to something more like
561 traditional Linux behavior, one can set an override for the
562 .BR systemd (1)
563 mechanism, using something like:
564 .P
565 .in +4n
566 .EX
567 .RB # " echo \[dq]kernel.core_pattern=core.%p\[dq] > \[rs]" ;
568 \f[B] /etc/sysctl.d/50\-coredump.conf\f[]
569 .RB # " /lib/systemd/systemd\-sysctl" ;
570 .EE
571 .in
572 .P
573 It is also possible to temporarily (i.e., until the next reboot) change the
574 .I core_pattern
575 setting using a command such as the following
576 (which causes the names of core dump files to include the executable name
577 as well as the number of the signal which triggered the core dump):
578 .P
579 .in +4n
580 .EX
581 .RB # " sysctl \-w kernel.core_pattern=\[dq]%e\-%s.core\[dq]" ;
582 .EE
583 .in
584 .\"
585 .SH NOTES
586 The
587 .BR gdb (1)
588 .I gcore
589 command can be used to obtain a core dump of a running process.
590 .P
591 In Linux versions up to and including 2.6.27,
592 .\" Changed with commit 6409324b385f3f63a03645b4422e3be67348d922
593 if a multithreaded process (or, more precisely, a process that
594 shares its memory with another process by being created with the
595 .B CLONE_VM
596 flag of
597 .BR clone (2))
598 dumps core, then the process ID is always appended to the core filename,
599 unless the process ID was already included elsewhere in the
600 filename via a
601 .I %p
602 specification in
603 .IR /proc/sys/kernel/core_pattern .
604 (This is primarily useful when employing the obsolete
605 LinuxThreads implementation,
606 where each thread of a process has a different PID.)
607 .\" Always including the PID in the name of the core file made
608 .\" sense for LinuxThreads, where each thread had a unique PID,
609 .\" but doesn't seem to serve any purpose with NPTL, where all the
610 .\" threads in a process share the same PID (as POSIX.1 requires).
611 .\" Probably the behavior is maintained so that applications using
612 .\" LinuxThreads continue appending the PID (the kernel has no easy
613 .\" way of telling which threading implementation the user-space
614 .\" application is using). -- mtk, April 2006
615 .SH EXAMPLES
616 The program below can be used to demonstrate the use of the
617 pipe syntax in the
618 .I /proc/sys/kernel/core_pattern
619 file.
620 The following shell session demonstrates the use of this program
621 (compiled to create an executable named
622 .IR core_pattern_pipe_test ):
623 .P
624 .in +4n
625 .EX
626 .RB "$" " cc \-o core_pattern_pipe_test core_pattern_pipe_test.c"
627 .RB "$" " su"
628 Password:
629 .RB "#" " echo \[dq]|$PWD/core_pattern_pipe_test %p UID=%u GID=%g sig=%s\[dq] > \[rs]"
630 .B " /proc/sys/kernel/core_pattern"
631 .RB "#" " exit"
632 .RB "$" " sleep 100"
633 .BR "\[ha]\[rs]" " # type control\-backslash"
634 Quit (core dumped)
635 .RB "$" " cat core.info"
636 argc=5
637 argc[0]=</home/mtk/core_pattern_pipe_test>
638 argc[1]=<20575>
639 argc[2]=<UID=1000>
640 argc[3]=<GID=100>
641 argc[4]=<sig=3>
642 Total bytes in core dump: 282624
643 .EE
644 .in
645 .SS Program source
646 \&
647 .EX
648 /* core_pattern_pipe_test.c */
649 \&
650 #define _GNU_SOURCE
651 #include <sys/stat.h>
652 #include <fcntl.h>
653 #include <limits.h>
654 #include <stdio.h>
655 #include <stdlib.h>
656 #include <unistd.h>
657 \&
658 #define BUF_SIZE 1024
659 \&
660 int
661 main(int argc, char *argv[])
662 {
663 ssize_t nread, tot;
664 char buf[BUF_SIZE];
665 FILE *fp;
666 char cwd[PATH_MAX];
667 \&
668 /* Change our current working directory to that of the
669 crashing process. */
670 \&
671 snprintf(cwd, PATH_MAX, "/proc/%s/cwd", argv[1]);
672 chdir(cwd);
673 \&
674 /* Write output to file "core.info" in that directory. */
675 \&
676 fp = fopen("core.info", "w+");
677 if (fp == NULL)
678 exit(EXIT_FAILURE);
679 \&
680 /* Display command\-line arguments given to core_pattern
681 pipe program. */
682 \&
683 fprintf(fp, "argc=%d\[rs]n", argc);
684 for (size_t j = 0; j < argc; j++)
685 fprintf(fp, "argc[%zu]=<%s>\[rs]n", j, argv[j]);
686 \&
687 /* Count bytes in standard input (the core dump). */
688 \&
689 tot = 0;
690 while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0)
691 tot += nread;
692 fprintf(fp, "Total bytes in core dump: %zd\[rs]n", tot);
693 \&
694 fclose(fp);
695 exit(EXIT_SUCCESS);
696 }
697 .EE
698 .SH SEE ALSO
699 .BR bash (1),
700 .BR coredumpctl (1),
701 .BR gdb (1),
702 .BR getrlimit (2),
703 .BR mmap (2),
704 .BR prctl (2),
705 .BR sigaction (2),
706 .BR elf (5),
707 .BR proc (5),
708 .BR pthreads (7),
709 .BR signal (7),
710 .BR systemd\-coredump (8)