mount_setattr.2: Reword the description of the 'propagation field'
[man-pages.git] / man5 / core.5
blobf1766a3c68b8100fa06ce5486585bdf67e809928
1 .\" Copyright (c) 2006, 2008 by Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH CORE 5 2021-03-22 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 core \- core dump file
28 .SH DESCRIPTION
29 The default action of certain signals is to cause a process to terminate
30 and produce a
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.,
35 .BR gdb (1))
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
38 .BR signal (7).
39 .PP
40 A process can set its soft
41 .B RLIMIT_CORE
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
44 .BR getrlimit (2)
45 for details.
46 .PP
47 There are various circumstances in which a core dump file is
48 not produced:
49 .IP * 3
50 The process does not have permission to write the core file.
51 (By default, the core file is called
52 .IR core
54 .IR core.pid ,
55 where
56 .I pid
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
63 is not writable
64 or is not a regular file
65 (e.g., it is a directory or a symbolic link).
66 .IP *
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
69 file.
70 .IP *
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.
74 .IP *
75 The directory in which the core dump file is to be created does
76 not exist.
77 .IP *
78 The
79 .B RLIMIT_CORE
80 (core file size) or
81 .B RLIMIT_FSIZE
82 (file size) resource limits for the process are set to zero; see
83 .BR getrlimit (2)
84 and the documentation of the shell's
85 .I ulimit
86 command
87 .RI ( limit
89 .BR csh (1)).
90 .IP *
91 The binary being executed by the process does not have read
92 permission enabled.
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.)
97 .IP *
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)
100 ID of the process,
101 or the process is executing a program that has file capabilities (see
102 .BR capabilities (7)).
103 (However, see the description of the
104 .BR prctl (2)
105 .B PR_SET_DUMPABLE
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?
110 file in
111 .BR proc (5).)
112 .IP *
113 .I /proc/sys/kernel/core_pattern
114 is empty and
115 .I /proc/sys/kernel/core_uses_pid
116 contains the value 0.
117 (These files are described below.)
118 Note that if
119 .I /proc/sys/kernel/core_pattern
120 is empty and
121 .I /proc/sys/kernel/core_uses_pid
122 contains the value 1,
123 core dump files will have names of the form
124 .IR .pid ,
125 and such files are hidden unless one uses the
126 .BR ls (1)
127 .I \-a
128 option.
129 .IP *
130 (Since Linux 3.7)
131 .\" commit 046d662f481830e652ac34cd112249adde16452a
132 The kernel was configured without the
133 .BR CONFIG_COREDUMP
134 option.
136 In addition,
137 a core dump may exclude part of the address space of the process if the
138 .BR madvise (2)
139 .B MADV_DONTDUMP
140 flag was employed.
142 On systems that employ
143 .BR systemd (1)
144 as the
145 .I init
146 framework, core dumps may instead be placed in a location determined by
147 .BR systemd (1).
148 See below for further details.
150 .SS Naming of core dump files
151 By default, a core dump file is named
152 .IR core ,
153 but the
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:
160 .RS 4
161 .PD 0
162 .TP 4
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
172 .BR prctl (2)
173 .B PR_GET_DUMPABLE
174 (since Linux 3.7).
177 The process or thread's
178 .I comm
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
183 .I /proc/[pid]/comm
185 .I /proc/[pid]/task/[tid]/comm
187 .BR proc (5).
190 Pathname of executable,
191 with slashes (\(aq/\(aq) replaced by exclamation marks (\(aq!\(aq)
192 (since Linux 3.0).
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
204 (since Linux 3.18).
207 TID of thread that triggered core dump, as seen in the initial PID namespace
208 .\" commit b03023ecbdb76c1dec86b41ed80b123c22783220
209 (since Linux 3.18).
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
218 (since Linux 3.12).
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
244 does not include
245 .I %p
247 .I /proc/sys/kernel/core_uses_pid
248 (see below)
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
252 crashing process.
253 That means the crashing process's mount namespace (see
254 .BR mount_namespaces (7)),
255 its current working directory (found via
256 .BR getcwd (2)),
257 and its root directory (see
258 .BR chroot (2)).
260 Since version 2.4, Linux has also provided
261 a more primitive method of controlling
262 the name of the core dump file.
263 If the
264 .I /proc/sys/kernel/core_uses_pid
265 file contains the value 0, then a core dump file is simply named
266 .IR core .
267 If this file contains a nonzero value, then the core dump file includes
268 the process ID in a name of the form
269 .IR core.PID .
271 Since Linux 3.6,
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
280 file.
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.
285 Since kernel 5.3.0,
286 .\" commit 315c69261dd3fa12dbc830d4fa00d1fad98d3b03
287 the pipe template is split on spaces into an argument list
288 .I before
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
293 .I %e
295 .I %E
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
300 in earlier kernels,
301 meaning that the core dump handler needs to use mechanisms to find
302 the executable name.
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:
307 .IP * 3
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.
311 .IP *
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
315 .I %p
316 in an argument.
317 .IP *
318 The process created to run the program runs as user and group
319 .IR root .
320 .IP *
321 Running as
322 .I root
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
326 .IR /proc/[pid] .
327 .IP *
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.
333 .IP *
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
338 .I %P
339 to find the right
340 .I /proc/[pid]
341 directory and probe/enter the crashing process's namespaces if needed.
342 .IP *
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
347 .I %P
348 specifier to change to the location of the dumping process via
349 .IR /proc/[pid]/cwd .
350 .IP *
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).
354 .IP *
356 .B RLIMIT_CORE
357 limit is not enforced for core dumps that are piped to a program
358 via this mechanism.
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
364 .IR /proc/[pid]
365 directory.
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
369 .IR /proc/[pid]
370 files prematurely.
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.
375 Since Linux 2.6.32,
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
400 .BR mmap (2)).
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:
405 .PD 0
406 .RS 4
408 bit 0
409 Dump anonymous private mappings.
411 bit 1
412 Dump anonymous shared mappings.
414 bit 2
415 Dump file-backed private mappings.
417 bit 3
418 Dump file-backed shared mappings.
419 .\" file-backed shared mappings of course also update the underlying
420 .\" mapped file.
422 bit 4 (since Linux 2.6.24)
423 Dump ELF headers.
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
445 .I coredump_filter
446 boot option.
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
452 virtual DSO
453 .RB ( vdso (7))
454 pages are always dumped, regardless of the
455 .I coredump_filter
456 value.
458 A child process created via
459 .BR fork (2)
460 inherits its parent's
461 .I coredump_filter
462 value;
464 .I coredump_filter
465 value is preserved across an
466 .BR execve (2).
468 It can be useful to set
469 .I coredump_filter
470 in the parent shell before running a program, for example:
472 .in +4n
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
480 .B CONFIG_ELF_CORE
481 configuration option.
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:
498 .in +4n
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),
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):
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.
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 .IR core
536 in the current directory, one could use:
538 .in +4n
540 $ \fBcoredumpctl dump 2955 \-o core\fP
544 For more extensive details, see the
545 .BR coredumpctl (1)
546 manual page.
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:
555 .in +4n
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
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):
569 .in +4n
571 # \fBsysctl \-w kernel.core_pattern="%e\-%s.core"\fP
575 .SH NOTES
577 .BR gdb (1)
578 .I gcore
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
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 ):
614 .in +4n
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 \
620 UID=%u GID=%g sig=%s\(dq > \e"
621 .B "    /proc/sys/kernel/core_pattern"
622 .RB "#" " exit"
623 .RB "$" " sleep 100"
624 .BR "\(ha\e" "                     # type control\-backslash"
625 Quit (core dumped)
626 .RB "$" " cat core.info"
627 argc=5
628 argc[0]=</home/mtk/core_pattern_pipe_test>
629 argc[1]=<20575>
630 argc[2]=<UID=1000>
631 argc[3]=<GID=100>
632 argc[4]=<sig=3>
633 Total bytes in core dump: 282624
636 .SS Program source
639 /* core_pattern_pipe_test.c */
641 #define _GNU_SOURCE
642 #include <sys/stat.h>
643 #include <fcntl.h>
644 #include <limits.h>
645 #include <stdio.h>
646 #include <stdlib.h>
647 #include <unistd.h>
649 #define BUF_SIZE 1024
652 main(int argc, char *argv[])
654     ssize_t nread, tot;
655     char buf[BUF_SIZE];
656     FILE *fp;
657     char cwd[PATH_MAX];
659     /* Change our current working directory to that of the
660        crashing process. */
662     snprintf(cwd, PATH_MAX, "/proc/%s/cwd", argv[1]);
663     chdir(cwd);
665     /* Write output to file "core.info" in that directory. */
667     fp = fopen("core.info", "w+");
668     if (fp == NULL)
669         exit(EXIT_FAILURE);
671     /* Display command\-line arguments given to core_pattern
672        pipe program. */
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). */
680     tot = 0;
681     while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0)
682         tot += nread;
683     fprintf(fp, "Total bytes in core dump: %zd\en", tot);
685     fclose(fp);
686     exit(EXIT_SUCCESS);
689 .SH SEE ALSO
690 .BR bash (1),
691 .BR coredumpctl (1),
692 .BR gdb (1),
693 .BR getrlimit (2),
694 .BR mmap (2),
695 .BR prctl (2),
696 .BR sigaction (2),
697 .BR elf (5),
698 .BR proc (5),
699 .BR pthreads (7),
700 .BR signal (7),
701 .BR systemd\-coredump (8)