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