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