Debian Codegraph @

upstream/mageia-cauldron/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-02-08 "Linux man-pages 6.17"
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 %d
158 .\" Added in git commit 12a2b4b2241e318b4f6df31228e4272d2c2968a1
159 Dump mode\[em]same as value returned by
160 .BR prctl (2)
161 .B PR_GET_DUMPABLE
162 (since Linux 3.7).
163 .TP
164 %e
165 The process or thread's
166 .I comm
167 value, which typically is the same as the executable filename
168 (without path prefix, and truncated to a maximum of 15 characters),
169 but may have been modified to be something different;
170 see the discussion of
171 .IR /proc/ pid /comm
172 and
173 .IR /proc/ pid /task/ tid /comm
174 in
175 .BR proc (5).
176 .TP
177 %E
178 Pathname of executable,
179 with slashes (\[aq]/\[aq]) replaced by exclamation marks (\[aq]!\[aq])
180 (since Linux 3.0).
181 .TP
182 %F
183 PIDFD of dumped process
184 .\" commit b5325b2a270fcaf7b2a9a0f23d422ca8a5a8bdea
185 (since Linux 6.16).
186 .TP
187 %g
188 Numeric real GID of dumped process.
189 .TP
190 %h
191 Hostname (same as
192 .I nodename
193 returned by
194 .BR uname (2)).
195 .TP
196 %i
197 TID of thread that triggered core dump,
198 as seen in the PID namespace in which the thread resides
199 .\" commit b03023ecbdb76c1dec86b41ed80b123c22783220
200 (since Linux 3.18).
201 .TP
202 %I
203 TID of thread that triggered core dump, as seen in the initial PID namespace
204 .\" commit b03023ecbdb76c1dec86b41ed80b123c22783220
205 (since Linux 3.18).
206 .TP
207 %p
208 PID of dumped process,
209 as seen in the PID namespace in which the process resides.
210 .TP
211 %P
212 .\" Added in git commit 65aafb1e7484b7434a0c1d4c593191ebe5776a2f
213 PID of dumped process, as seen in the initial PID namespace
214 (since Linux 3.12).
215 .TP
216 %s
217 Number of signal causing dump.
218 .TP
219 %t
220 Time of dump, expressed as seconds since the
221 Epoch, 1970-01-01 00:00:00 +0000 (UTC).
222 .TP
223 %u
224 Numeric real UID of dumped process.
225 .PD
226 .RE
227 .P
228 A single % at the end of the template is dropped from the
229 core filename, as is the combination of a % followed by any
230 character other than those listed above.
231 All other characters in the template become a literal
232 part of the core filename.
233 The template may include \[aq]/\[aq] characters, which are interpreted
234 as delimiters for directory names.
235 The maximum size of the resulting core filename is 128 bytes (64 bytes
236 before Linux 2.6.19).
237 The default value in this file is "core".
238 For backward compatibility, if
239 .I /proc/sys/kernel/core_pattern
240 does not include
241 .I %p
242 and
243 .I /proc/sys/kernel/core_uses_pid
244 (see below)
245 is nonzero, then .PID will be appended to the core filename.
246 .P
247 Paths are interpreted according to the settings that are active for the
248 crashing process.
249 That means the crashing process's mount namespace (see
250 .BR mount_namespaces (7)),
251 its current working directory (found via
252 .BR getcwd (2)),
253 and its root directory (see
254 .BR chroot (2)).
255 .P
256 Since Linux 2.4, Linux has also provided
257 a more primitive method of controlling
258 the name of the core dump file.
259 If the
260 .I /proc/sys/kernel/core_uses_pid
261 file contains the value 0, then a core dump file is simply named
262 .IR core .
263 If this file contains a nonzero value, then the core dump file includes
264 the process ID in a name of the form
265 .IR core.PID .
266 .P
267 Since Linux 3.6,
268 .\" 9520628e8ceb69fa9a4aee6b57f22675d9e1b709
269 if
270 .I /proc/sys/fs/suid_dumpable
271 is set to 2 ("suidsafe"), the pattern must be either an absolute pathname
272 (starting with a leading \[aq]/\[aq] character) or a pipe, as defined below.
273 .SS Piping core dumps to a program
274 Since Linux 2.6.19, Linux supports an alternate syntax for the
275 .I /proc/sys/kernel/core_pattern
276 file.
277 If the first character of this file is a pipe symbol
278 .RI ( | ),
279 then the remainder of the line is interpreted as the command-line for
280 a user-space program (or script) that is to be executed.
281 .P
282 Since Linux 5.3.0,
283 .\" commit 315c69261dd3fa12dbc830d4fa00d1fad98d3b03
284 the pipe template is split on spaces into an argument list
285 .I before
286 the template parameters are expanded.
287 In earlier kernels, the template parameters are expanded first and
288 the resulting string is split on spaces into an argument list.
289 This means that in earlier kernels executable names added by the
290 .I %e
291 and
292 .I %E
293 template parameters could get split into multiple arguments.
294 So the core dump handler needs to put the executable names as the last
295 argument and ensure it joins all parts of the executable name using spaces.
296 Executable names with multiple spaces in them are not correctly represented
297 in earlier kernels,
298 meaning that the core dump handler needs to use mechanisms to find
299 the executable name.
300 .P
301 Instead of being written to a file, the core dump is given as
302 standard input to the program.
303 Note the following points:
304 .IP \[bu] 3
305 The program must be specified using an absolute pathname (or a
306 pathname relative to the root directory,
307 .IR / ),
308 and must immediately follow the '|' character.
309 .IP \[bu]
310 The command-line arguments can include any of
311 the % specifiers listed above.
312 For example, to pass the PID of the process that is being dumped, specify
313 .I %p
314 in an argument.
315 .IP \[bu]
316 The process created to run the program runs as user and group
317 .IR root .
318 .IP \[bu]
319 Running as
320 .I root
321 does not confer any exceptional security bypasses.
322 Namely, LSMs (e.g., SELinux) are still active and may prevent the handler
323 from accessing details about the crashed process via
324 .IR /proc/ pid.
325 .IP \[bu]
326 The program pathname is interpreted with respect to the initial mount namespace
327 as it is always executed there.
328 It is not affected by the settings
329 (e.g., root directory, mount namespace, current working directory)
330 of the crashing process.
331 .IP \[bu]
332 The process runs in the initial namespaces
333 (PID, mount, user, and so on)
334 and not in the namespaces of the crashing process.
335 One can utilize specifiers such as
336 .I %P
337 to find the right
338 .IR /proc/ pid
339 directory and probe/enter the crashing process's namespaces if needed.
340 .IP \[bu]
341 The process starts with its current working directory
342 as the root directory.
343 If desired, it is possible change to the working directory of
344 the dumping process by employing the value provided by the
345 .I %P
346 specifier to change to the location of the dumping process via
347 .IR /proc/ pid /cwd .
348 .IP \[bu]
349 Command-line arguments can be supplied to the
350 program (since Linux 2.6.24),
351 delimited by white space (up to a total line length of 128 bytes).
352 .IP \[bu]
353 The
354 .B RLIMIT_CORE
355 limit is not enforced for core dumps that are piped to a program
356 via this mechanism.
357 .\"
358 .SS /proc/sys/kernel/core_pipe_limit
359 When collecting core dumps via a pipe to a user-space program,
360 it can be useful for the collecting program to gather data about
361 the crashing process from that process's
362 .IR /proc/ pid
363 directory.
364 In order to do this safely,
365 the kernel must wait for the program collecting the core dump to exit,
366 so as not to remove the crashing process's
367 .IR /proc/ pid
368 files prematurely.
369 This in turn creates the
370 possibility that a misbehaving collecting program can block
371 the reaping of a crashed process by simply never exiting.
372 .P
373 Since Linux 2.6.32,
374 .\" commit a293980c2e261bd5b0d2a77340dd04f684caff58
375 the
376 .I /proc/sys/kernel/core_pipe_limit
377 can be used to defend against this possibility.
378 The value in this file defines how many concurrent crashing
379 processes may be piped to user-space programs in parallel.
380 If this value is exceeded, then those crashing processes above this value
381 are noted in the kernel log and their core dumps are skipped.
382 .P
383 A value of 0 in this file is special.
384 It indicates that unlimited processes may be captured in parallel,
385 but that no waiting will take place (i.e., the collecting
386 program is not guaranteed access to
387 .IR /proc/<crashing\-PID> ).
388 The default value for this file is 0.
389 .\"
390 .SS Controlling which mappings are written to the core dump
391 Since Linux 2.6.23, the Linux-specific
392 .IR /proc/ pid /coredump_filter
393 file can be used to control which memory segments are written to the
394 core dump file in the event that a core dump is performed for the
395 process with the corresponding process ID.
396 .P
397 The value in the file is a bit mask of memory mapping types (see
398 .BR mmap (2)).
399 If a bit is set in the mask,
400 then memory mappings of the corresponding type are dumped;
401 otherwise,
402 they are not dumped.
403 The bits in this file have the following meanings:
404 .P
405 .PD 0
406 .RS 4
407 .TP
408 bit 0
409 Dump anonymous private mappings.
410 .TP
411 bit 1
412 Dump anonymous shared mappings.
413 .TP
414 bit 2
415 Dump file-backed private mappings.
416 .TP
417 bit 3
418 Dump file-backed shared mappings.
419 .\" file-backed shared mappings of course also update the underlying
420 .\" mapped file.
421 .TP
422 bit 4 (since Linux 2.6.24)
423 Dump ELF headers.
424 .TP
425 bit 5 (since Linux 2.6.28)
426 Dump private huge pages.
427 .TP
428 bit 6 (since Linux 2.6.28)
429 Dump shared huge pages.
430 .TP
431 bit 7 (since Linux 4.4)
432 .\" commit ab27a8d04b32b6ee8c30c14c4afd1058e8addc82
433 Dump private DAX pages.
434 .TP
435 bit 8 (since Linux 4.4)
436 .\" commit ab27a8d04b32b6ee8c30c14c4afd1058e8addc82
437 Dump shared DAX pages.
438 .RE
439 .PD
440 .P
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
445 .I coredump_filter
446 boot option.
447 .P
448 The value of this file is displayed in hexadecimal.
449 (The default value is thus displayed as 33.)
450 .P
451 Memory-mapped I/O pages such as frame buffer are never dumped, and
452 virtual DSO
453 .RB ( vdso (7))
454 pages are always dumped, regardless of the
455 .I coredump_filter
456 value.
457 .P
458 A child process created via
459 .BR fork (2)
460 inherits its parent's
461 .I coredump_filter
462 value;
463 the
464 .I coredump_filter
465 value is preserved across an
466 .BR execve (2).
467 .P
468 It can be useful to set
469 .I coredump_filter
470 in the parent shell before running a program, for example:
471 .P
472 .in +4n
473 .EX
474 .RB "$" " echo 0x7 > /proc/self/coredump_filter"
475 .RB "$" " ./some_program"
476 .EE
477 .in
478 .P
479 This file is provided only if the kernel was built with the
480 .B CONFIG_ELF_CORE
481 configuration option.
482 .\"
483 .SS Core dumps and systemd
484 On systems using the
485 .BR systemd (1)
486 .I init
487 framework, core dumps may be placed in a location determined by
488 .BR systemd (1).
489 To do this,
490 .BR systemd (1)
491 employs the
492 .I core_pattern
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)
496 program:
497 .P
498 .in +4n
499 .EX
500 .RB $ " cat /proc/sys/kernel/core_pattern" ;
501 |/usr/lib/systemd/systemd\-coredump %P %u %g %s %t %c %e
502 .EE
503 .in
504 .P
505 In this case, core dumps will be placed in the location configured for
506 .BR systemd\-coredump (8),
507 typically as
508 .BR lz4 (1)
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)
513 using
514 .BR coredumpctl (1):
515 .P
516 .EX
517 .RB $ " coredumpctl list | tail \-5" ;
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
523 .EE
524 .P
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.
529 Various options to
530 .BR coredumpctl (1)
531 allow a specified coredump file to be pulled from the
532 .BR systemd (1)
533 location into a specified file.
534 For example, to extract the core dump for PID 2955 shown above to a file named
535 .I core
536 in the current directory, one could use:
537 .P
538 .in +4n
539 .EX
540 .RB $ " coredumpctl dump 2955 \-o core" ;
541 .EE
542 .in
543 .P
544 For more extensive details, see the
545 .BR coredumpctl (1)
546 manual page.
547 .P
548 To (persistently) disable the
549 .BR systemd (1)
550 mechanism that archives core dumps, restoring to something more like
551 traditional Linux behavior, one can set an override for the
552 .BR systemd (1)
553 mechanism, using something like:
554 .P
555 .in +4n
556 .EX
557 .RB # " echo \[dq]kernel.core_pattern=core.%p\[dq] > \[rs]" ;
558 \f[B] /etc/sysctl.d/50\-coredump.conf\f[]
559 .RB # " /lib/systemd/systemd\-sysctl" ;
560 .EE
561 .in
562 .P
563 It is also possible to temporarily (i.e., until the next reboot) change the
564 .I core_pattern
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):
568 .P
569 .in +4n
570 .EX
571 .RB # " sysctl \-w kernel.core_pattern=\[dq]%e\-%s.core\[dq]" ;
572 .EE
573 .in
574 .\"
575 .SH NOTES
576 The
577 .BR gdb (1)
578 .I gcore
579 command can be used to obtain a core dump of a running process.
580 .P
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
585 .B CLONE_VM
586 flag of
587 .BR clone (2))
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
590 filename via a
591 .I %p
592 specification in
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
605 .SH EXAMPLES
606 The program below can be used to demonstrate the use of the
607 pipe syntax in the
608 .I /proc/sys/kernel/core_pattern
609 file.
610 The following shell session demonstrates the use of this program
611 (compiled to create an executable named
612 .IR core_pattern_pipe_test ):
613 .P
614 .in +4n
615 .EX
616 .RB "$" " cc \-o core_pattern_pipe_test core_pattern_pipe_test.c"
617 .RB "$" " su"
618 Password:
619 .RB "#" " echo \[dq]|$PWD/core_pattern_pipe_test %p UID=%u GID=%g sig=%s\[dq] > \[rs]"
620 .B " /proc/sys/kernel/core_pattern"
621 .RB "#" " exit"
622 .RB "$" " sleep 100"
623 .BR "\[ha]\[rs]" " # type control\-backslash"
624 Quit (core dumped)
625 .RB "$" " cat core.info"
626 argc=5
627 argc[0]=</home/mtk/core_pattern_pipe_test>
628 argc[1]=<20575>
629 argc[2]=<UID=1000>
630 argc[3]=<GID=100>
631 argc[4]=<sig=3>
632 Total bytes in core dump: 282624
633 .EE
634 .in
635 .SS Program source
636 \&
637 .EX
638 /* core_pattern_pipe_test.c */
639 \&
640 #define _GNU_SOURCE
641 #include <sys/stat.h>
642 #include <fcntl.h>
643 #include <limits.h>
644 #include <stdio.h>
645 #include <stdlib.h>
646 #include <unistd.h>
647 \&
648 #define BUF_SIZE 1024
649 \&
650 int
651 main(int argc, char *argv[])
652 {
653 ssize_t nread, tot;
654 char buf[BUF_SIZE];
655 FILE *fp;
656 char cwd[PATH_MAX];
657 \&
658 /* Change our current working directory to that of the
659 crashing process. */
660 \&
661 snprintf(cwd, PATH_MAX, "/proc/%s/cwd", argv[1]);
662 chdir(cwd);
663 \&
664 /* Write output to file "core.info" in that directory. */
665 \&
666 fp = fopen("core.info", "w+");
667 if (fp == NULL)
668 exit(EXIT_FAILURE);
669 \&
670 /* Display command\-line arguments given to core_pattern
671 pipe program. */
672 \&
673 fprintf(fp, "argc=%d\[rs]n", argc);
674 for (size_t j = 0; j < argc; j++)
675 fprintf(fp, "argc[%zu]=<%s>\[rs]n", j, argv[j]);
676 \&
677 /* Count bytes in standard input (the core dump). */
678 \&
679 tot = 0;
680 while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0)
681 tot += nread;
682 fprintf(fp, "Total bytes in core dump: %zd\[rs]n", tot);
683 \&
684 fclose(fp);
685 exit(EXIT_SUCCESS);
686 }
687 .EE
688 .SH SEE ALSO
689 .BR bash (1),
690 .BR coredumpctl (1),
691 .BR gdb (1),
692 .BR getrlimit (2),
693 .BR mmap (2),
694 .BR prctl (2),
695 .BR sigaction (2),
696 .BR elf (5),
697 .BR proc (5),
698 .BR pthreads (7),
699 .BR signal (7),
700 .BR systemd\-coredump (8)