1 .\" Copyright (c) 2006, 2008 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .TH CORE 5 2010-02-25 "Linux" "Linux Programmer's Manual"
25 core \- core dump file
27 The default action of certain signals is to cause a process to terminate
29 .IR "core dump file" ,
30 a disk file containing an image of the process's memory at
31 the time of termination.
32 This image can be used in a debugger (e.g.,
34 to inspect the state of the program at the time that it terminated.
35 A list of the signals which cause a process to dump core can be found in
38 A process can set its soft
40 resource limit to place an upper limit on the size of the core dump file
41 that will be produced if it receives a "core dump" signal; see
45 There are various circumstances in which a core dump file is
48 The process does not have permission to write the core file.
49 (By default the core file is called
51 and is created in the current working directory.
52 See below for details on naming.)
53 Writing the core file will fail if the directory in which
54 it is to be created is nonwritable,
55 or if a file with the same name exists and
57 or is not a regular file
58 (e.g., it is a directory or a symbolic link).
60 A (writable, regular) file with the same name as would be used for the
61 core dump already exists, but there is more than one hard link to that
64 The file system where the core dump file would be created is full;
65 or has run out of inodes; or is mounted read-only;
66 or the user has reached their quota for the file system.
68 The directory in which the core dump file is to be created does
75 (file size) resource limits for the process are set to zero; see
77 and the documentation of the shell's
84 The binary being executed by the process does not have read
87 The process is executing a set-user-ID (set-group-ID) program
88 that is owned by a user (group) other than the real user (group)
90 (However, see the description of the
93 operation, and the description of the
94 .I /proc/sys/fs/suid_dumpable
95 .\" FIXME . Perhaps relocate discussion of /proc/sys/fs/suid_dumpable
96 .\" and PR_SET_DUMPABLE to this page?
99 .SS Naming of core dump files
100 By default, a core dump file is named
103 .I /proc/sys/kernel/core_pattern
104 file (since Linux 2.6 and 2.4.21)
105 can be set to define a template that is used to name core dump files.
106 The template can contain % specifiers which are substituted
107 by the following values when a core file is created:
116 PID of dumped process
119 (numeric) real UID of dumped process
122 (numeric) real GID of dumped process
125 number of signal causing dump
128 time of dump, expressed as seconds since the
129 Epoch, 1970-01-01 00:00:00 +0000 (UTC)
132 hostname (same as \fInodename\fP returned by \fBuname\fP(2))
135 executable filename (without path prefix)
138 core file size soft resource limit of crashing process (since Linux 2.6.24)
142 A single % at the end of the template is dropped from the
143 core filename, as is the combination of a % followed by any
144 character other than those listed above.
145 All other characters in the template become a literal
146 part of the core filename.
147 The template may include \(aq/\(aq characters, which are interpreted
148 as delimiters for directory names.
149 The maximum size of the resulting core filename is 128 bytes (64 bytes
150 in kernels before 2.6.19).
151 The default value in this file is "core".
152 For backward compatibility, if
153 .I /proc/sys/kernel/core_pattern
154 does not include "%p" and
155 .I /proc/sys/kernel/core_uses_pid
157 is nonzero, then .PID will be appended to the core filename.
159 Since version 2.4, Linux has also provided
160 a more primitive method of controlling
161 the name of the core dump file.
163 .I /proc/sys/kernel/core_uses_pid
164 file contains the value 0, then a core dump file is simply named
166 If this file contains a nonzero value, then the core dump file includes
167 the process ID in a name of the form
169 .SS Piping core dumps to a program
170 Since kernel 2.6.19, Linux supports an alternate syntax for the
171 .I /proc/sys/kernel/core_pattern
173 If the first character of this file is a pipe symbol (\fB|\fP),
174 then the remainder of the line is interpreted as a program to be
176 Instead of being written to a disk file, the core dump is given as
177 standard input to the program.
178 Note the following points:
180 The program must be specified using an absolute pathname (or a
181 pathname relative to the root directory, \fI/\fP),
182 and must immediately follow the '|' character.
184 The process created to run the program runs as user and group
187 Command-line arguments can be supplied to the
188 program (since kernel 2.6.24),
189 delimited by white space (up to a total line length of 128 bytes).
191 The command-line arguments can include any of
192 the % specifiers listed above.
193 For example, to pass the PID of the process that is being dumped, specify
196 .SS Controlling which mappings are written to the core dump
197 Since kernel 2.6.23, the Linux-specific
198 .IR /proc/PID/coredump_filter
199 file can be used to control which memory segments are written to the
200 core dump file in the event that a core dump is performed for the
201 process with the corresponding process ID.
203 The value in the file is a bit mask of memory mapping types (see
205 If a bit is set in the mask, then memory mappings of the
206 corresponding type are dumped; otherwise they are not dumped.
207 The bits in this file have the following meanings:
213 Dump anonymous private mappings.
216 Dump anonymous shared mappings.
219 Dump file-backed private mappings.
222 Dump file-backed shared mappings.
223 .\" file-backed shared mappings of course also update the underlying
231 this reflects traditional Linux behavior and means that
232 only anonymous memory segments are dumped.
234 Memory-mapped I/O pages such as frame buffer are never dumped, and
235 virtual DSO pages are always dumped, regardless of the
239 A child process created via
246 value is preserved across an
249 It can be useful to set
251 in the parent shell before running a program, for example:
255 .RB "$" " echo 0x7 > /proc/self/coredump_filter"
256 .RB "$" " ./some_program"
260 This file is only provided if the kernel was built with the
262 configuration option.
267 command can be used to obtain a core dump of a running process.
269 If a multithreaded process (or, more precisely, a process that
270 shares its memory with another process by being created with the
274 dumps core, then the process ID is always appended to the core filename,
275 unless the process ID was already included elsewhere in the
276 filename via a %p specification in
277 .IR /proc/sys/kernel/core_pattern .
278 (This is primarily useful when employing the LinuxThreads implementation,
279 where each thread of a process has a different PID.)
280 .\" Always including the PID in the name of the core file made
281 .\" sense for LinuxThreads, where each thread had a unique PID,
282 .\" but doesn't seem to serve any purpose with NPTL, where all the
283 .\" threads in a process share the same PID (as POSIX.1 requires).
284 .\" Probably the behavior is maintained so that applications using
285 .\" LinuxThreads continue appending the PID (the kernel has no easy
286 .\" way of telling which threading implementation the userspace
287 .\" application is using). -- mtk, April 2006
289 The program below can be used to demonstrate the use of the
291 .I /proc/sys/kernel/core_pattern
293 The following shell session demonstrates the use of this program
294 (compiled to create an executable named
295 .IR core_pattern_pipe_test ):
299 .RB "$" " cc \-o core_pattern_pipe_test core_pattern_pipe_test.c"
302 .RB "#" " echo \(aq|$PWD/core_pattern_pipe_test %p \
303 UID=%u GID=%g sig=%s\(aq > \e"
304 .B " /proc/sys/kernel/core_pattern"
307 .BR "^\e" " # type control-backslash"
309 .RB "$" " cat core.info"
311 argc[0]=</home/mtk/core_pattern_pipe_test>
316 Total bytes in core dump: 282624
322 /* core_pattern_pipe_test.c */
325 #include <sys/stat.h>
332 #define BUF_SIZE 1024
335 main(int argc, char *argv[])
343 /* Change our current working directory to that of the
346 snprintf(cwd, PATH_MAX, "/proc/%s/cwd", argv[1]);
349 /* Write output to file "core.info" in that directory */
351 fp = fopen("core.info", "w+");
355 /* Display command\-line arguments given to core_pattern
358 fprintf(fp, "argc=%d\\n", argc);
359 for (j = 0; j < argc; j++)
360 fprintf(fp, "argc[%d]=<%s>\\n", j, argv[j]);
362 /* Count bytes in standard input (the core dump) */
365 while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0)
367 fprintf(fp, "Total bytes in core dump: %d\\n", tot);