1 .\" Copyright (c) 2006, 2008 by Michael Kerrisk <mtk.manpages@gmail.com>
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH CORE 5 2014-01-24 "Linux" "Linux Programmer's Manual"
27 core \- core dump file
29 The default action of certain signals is to cause a process to terminate
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.,
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
40 A process can set its soft
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
47 There are various circumstances in which a core dump file is
50 The process does not have permission to write the core file.
51 (By default the core file is called
53 and is created in the current working directory.
54 See below for details on naming.)
55 Writing the core file will fail if the directory in which
56 it is to be created is nonwritable,
57 or if a file with the same name exists and
59 or is not a regular file
60 (e.g., it is a directory or a symbolic link).
62 A (writable, regular) file with the same name as would be used for the
63 core dump already exists, but there is more than one hard link to that
66 The filesystem where the core dump file would be created is full;
67 or has run out of inodes; or is mounted read-only;
68 or the user has reached their quota for the filesystem.
70 The directory in which the core dump file is to be created does
77 (file size) resource limits for the process are set to zero; see
79 and the documentation of the shell's
86 The binary being executed by the process does not have read
89 The process is executing a set-user-ID (set-group-ID) program
90 that is owned by a user (group) other than the real user (group)
92 (However, see the description of the
95 operation, and the description of the
96 .I /proc/sys/fs/suid_dumpable
97 .\" FIXME . Perhaps relocate discussion of /proc/sys/fs/suid_dumpable
98 .\" and PR_SET_DUMPABLE to this page?
103 .\" commit 046d662f481830e652ac34cd112249adde16452a
104 The kernel was configured without the
109 a core dump may exclude part of the address space of the process if the
113 .SS Naming of core dump files
114 By default, a core dump file is named
117 .I /proc/sys/kernel/core_pattern
118 file (since Linux 2.6 and 2.4.21)
119 can be set to define a template that is used to name core dump files.
120 The template can contain % specifiers which are substituted
121 by the following values when a core file is created:
130 PID of dumped process (as seen in the current namespace)
132 .\" Added in git commit 65aafb1e7484b7434a0c1d4c593191ebe5776a2f
134 global PID of dumped process (as seen in init's namespace)
138 (numeric) real UID of dumped process
141 (numeric) real GID of dumped process
144 number of signal causing dump
147 time of dump, expressed as seconds since the
148 Epoch, 1970-01-01 00:00:00 +0000 (UTC)
151 hostname (same as \fInodename\fP returned by \fBuname\fP(2))
154 executable filename (without path prefix)
157 pathname of executable,
158 with slashes (\(aq/\(aq) replaced by exclamation marks (\(aq!\(aq)
162 core file size soft resource limit of crashing process (since Linux 2.6.24)
166 A single % at the end of the template is dropped from the
167 core filename, as is the combination of a % followed by any
168 character other than those listed above.
169 All other characters in the template become a literal
170 part of the core filename.
171 The template may include \(aq/\(aq characters, which are interpreted
172 as delimiters for directory names.
173 The maximum size of the resulting core filename is 128 bytes (64 bytes
174 in kernels before 2.6.19).
175 The default value in this file is "core".
176 For backward compatibility, if
177 .I /proc/sys/kernel/core_pattern
178 does not include "%p" and
179 .I /proc/sys/kernel/core_uses_pid
181 is nonzero, then .PID will be appended to the core filename.
183 Since version 2.4, Linux has also provided
184 a more primitive method of controlling
185 the name of the core dump file.
187 .I /proc/sys/kernel/core_uses_pid
188 file contains the value 0, then a core dump file is simply named
190 If this file contains a nonzero value, then the core dump file includes
191 the process ID in a name of the form
195 .\" 9520628e8ceb69fa9a4aee6b57f22675d9e1b709
197 .I /proc/sys/fs/suid_dumpable
198 is set to 2 ("suidsafe"), the pattern must be either an absolute pathname
199 (starting with a leading \(aq/\(aq character) or a pipe, as defined below.
200 .SS Piping core dumps to a program
201 Since kernel 2.6.19, Linux supports an alternate syntax for the
202 .I /proc/sys/kernel/core_pattern
204 If the first character of this file is a pipe symbol (\fB|\fP),
205 then the remainder of the line is interpreted as a program to be
207 Instead of being written to a disk file, the core dump is given as
208 standard input to the program.
209 Note the following points:
211 The program must be specified using an absolute pathname (or a
212 pathname relative to the root directory, \fI/\fP),
213 and must immediately follow the '|' character.
215 The process created to run the program runs as user and group
218 Command-line arguments can be supplied to the
219 program (since Linux 2.6.24),
220 delimited by white space (up to a total line length of 128 bytes).
222 The command-line arguments can include any of
223 the % specifiers listed above.
224 For example, to pass the PID of the process that is being dumped, specify
227 .SS Controlling which mappings are written to the core dump
228 Since kernel 2.6.23, the Linux-specific
229 .IR /proc/PID/coredump_filter
230 file can be used to control which memory segments are written to the
231 core dump file in the event that a core dump is performed for the
232 process with the corresponding process ID.
234 The value in the file is a bit mask of memory mapping types (see
236 If a bit is set in the mask, then memory mappings of the
237 corresponding type are dumped; otherwise they are not dumped.
238 The bits in this file have the following meanings:
244 Dump anonymous private mappings.
247 Dump anonymous shared mappings.
250 Dump file-backed private mappings.
253 Dump file-backed shared mappings.
254 .\" file-backed shared mappings of course also update the underlying
257 bit 4 (since Linux 2.6.24)
260 bit 5 (since Linux 2.6.28)
261 Dump private huge pages.
263 bit 6 (since Linux 2.6.28)
264 Dump shared huge pages.
268 By default, the following bits are set: 0, 1, 4 (if the
269 .B CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS
270 kernel configuration option is enabled), and 5.
271 The value of this file is displayed in hexadecimal.
272 (The default value is thus displayed as 33.)
274 Memory-mapped I/O pages such as frame buffer are never dumped, and
275 virtual DSO pages are always dumped, regardless of the
279 A child process created via
281 inherits its parent's
286 value is preserved across an
289 It can be useful to set
291 in the parent shell before running a program, for example:
295 .RB "$" " echo 0x7 > /proc/self/coredump_filter"
296 .RB "$" " ./some_program"
300 This file is provided only if the kernel was built with the
302 configuration option.
307 command can be used to obtain a core dump of a running process.
309 In Linux versions up to and including 2.6.27,
310 .\" Changed with commit 6409324b385f3f63a03645b4422e3be67348d922
311 if a multithreaded process (or, more precisely, a process that
312 shares its memory with another process by being created with the
316 dumps core, then the process ID is always appended to the core filename,
317 unless the process ID was already included elsewhere in the
318 filename via a %p specification in
319 .IR /proc/sys/kernel/core_pattern .
320 (This is primarily useful when employing the obsolete
321 LinuxThreads implementation,
322 where each thread of a process has a different PID.)
323 .\" Always including the PID in the name of the core file made
324 .\" sense for LinuxThreads, where each thread had a unique PID,
325 .\" but doesn't seem to serve any purpose with NPTL, where all the
326 .\" threads in a process share the same PID (as POSIX.1 requires).
327 .\" Probably the behavior is maintained so that applications using
328 .\" LinuxThreads continue appending the PID (the kernel has no easy
329 .\" way of telling which threading implementation the user-space
330 .\" application is using). -- mtk, April 2006
332 The program below can be used to demonstrate the use of the
334 .I /proc/sys/kernel/core_pattern
336 The following shell session demonstrates the use of this program
337 (compiled to create an executable named
338 .IR core_pattern_pipe_test ):
342 .RB "$" " cc \-o core_pattern_pipe_test core_pattern_pipe_test.c"
345 .RB "#" " echo \(dq|$PWD/core_pattern_pipe_test %p \
346 UID=%u GID=%g sig=%s\(dq > \e"
347 .B " /proc/sys/kernel/core_pattern"
350 .BR "^\e" " # type control-backslash"
352 .RB "$" " cat core.info"
354 argc[0]=</home/mtk/core_pattern_pipe_test>
359 Total bytes in core dump: 282624
365 /* core_pattern_pipe_test.c */
368 #include <sys/stat.h>
375 #define BUF_SIZE 1024
378 main(int argc, char *argv[])
386 /* Change our current working directory to that of the
389 snprintf(cwd, PATH_MAX, "/proc/%s/cwd", argv[1]);
392 /* Write output to file "core.info" in that directory */
394 fp = fopen("core.info", "w+");
398 /* Display command\-line arguments given to core_pattern
401 fprintf(fp, "argc=%d\\n", argc);
402 for (j = 0; j < argc; j++)
403 fprintf(fp, "argc[%d]=<%s>\\n", j, argv[j]);
405 /* Count bytes in standard input (the core dump) */
408 while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0)
410 fprintf(fp, "Total bytes in core dump: %d\\n", tot);