]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man5/core.5
eventfd.2, getdents.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace...
[thirdparty/man-pages.git] / man5 / core.5
1 .\" Copyright (c) 2006, 2008 by Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
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.
6 .\"
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.
11 .\"
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
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .TH CORE 5 2008-08-26 "Linux" "Linux Programmer's Manual"
24 .SH NAME
25 core \- core dump file
26 .SH DESCRIPTION
27 The default action of certain signals is to cause a process to terminate
28 and produce a
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.,
33 .BR gdb (1))
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
36 .BR signal (7).
37
38 A process can set its soft
39 .B RLIMIT_CORE
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
42 .BR getrlimit (2)
43 for details.
44
45 There are various circumstances in which a core dump file is
46 not produced:
47 .IP * 3
48 The process does not have permission to write the core file.
49 (By default the core file is called
50 .IR core ,
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 non-writable,
55 or if a file with the same name exists and
56 is not writable
57 or is not a regular file
58 (e.g., it is a directory or a symbolic link).
59 .IP *
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
62 file.
63 .IP *
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.
67 .IP *
68 The directory in which the core dump file is to be created does
69 not exist.
70 .IP *
71 The
72 .B RLIMIT_CORE
73 (core file size) or
74 .B RLIMIT_FSIZE
75 (file size) resource limits for the process are set to zero; see
76 .BR getrlimit (2)
77 and the documentation of the shell's
78 .I ulimit
79 command
80 .RI ( limit
81 in
82 .BR csh (1)).
83 .IP *
84 The binary being executed by the process does not have read
85 permission enabled.
86 .IP *
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)
89 ID of the process.
90 (However, see the description of the
91 .BR prctl (2)
92 .B PR_SET_DUMPABLE
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?
97 file in
98 .BR proc (5).)
99 .SS Naming of core dump files
100 By default, a core dump file is named
101 .IR core ,
102 but the
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:
108 .PP
109 .RS 4
110 .PD 0
111 .TP 4
112 %%
113 a single % character
114 .TP
115 %p
116 PID of dumped process
117 .TP
118 %u
119 (numeric) real UID of dumped process
120 .TP
121 %g
122 (numeric) real GID of dumped process
123 .TP
124 %s
125 number of signal causing dump
126 .TP
127 %t
128 time of dump, expressed as seconds since the Epoch (00:00h, 1\ Jan 1970, UTC)
129 .TP
130 %h
131 hostname (same as \fInodename\fP returned by \fBuname\fP(2))
132 .TP
133 %e
134 executable filename (without path prefix)
135 .TP
136 %c
137 core file size soft resource limit of crashing process (since Linux 2.6.24)
138 .PD
139 .RE
140 .PP
141 A single % at the end of the template is dropped from the
142 core filename, as is the combination of a % followed by any
143 character other than those listed above.
144 All other characters in the template become a literal
145 part of the core filename.
146 The template may include \(aq/\(aq characters, which are interpreted
147 as delimiters for directory names.
148 The maximum size of the resulting core filename is 128 bytes (64 bytes
149 in kernels before 2.6.19).
150 The default value in this file is "core".
151 For backward compatibility, if
152 .I /proc/sys/kernel/core_pattern
153 does not include "%p" and
154 .I /proc/sys/kernel/core_uses_pid
155 (see below)
156 is non-zero, then .PID will be appended to the core filename.
157
158 Since version 2.4, Linux has also provided
159 a more primitive method of controlling
160 the name of the core dump file.
161 If the
162 .I /proc/sys/kernel/core_uses_pid
163 file contains the value 0, then a core dump file is simply named
164 .IR core .
165 If this file contains a non-zero value, then the core dump file includes
166 the process ID in a name of the form
167 .IR core.PID .
168 .SS Piping core dumps to a program
169 Since kernel 2.6.19, Linux supports an alternate syntax for the
170 .I /proc/sys/kernel/core_pattern
171 file.
172 If the first character of this file is a pipe symbol (\fB|\fP),
173 then the remainder of the line is interpreted as a program to be
174 executed.
175 Instead of being written to a disk file, the core dump is given as
176 standard input to the program.
177 Note the following points:
178 .IP * 3
179 The program must be specified using an absolute pathname (or a
180 pathname relative to the root directory, \fI/\fP),
181 and must immediately follow the '|' character.
182 .IP *
183 The process created to run the program runs as user and group
184 .IR root .
185 .IP *
186 Command-line arguments can be supplied to the
187 program (since kernel 2.6.24),
188 delimited by white space (up to a total line length of 128 bytes).
189 .IP *
190 The command-line arguments can include any of
191 the % specifiers listed above.
192 For example, to pass the PID of the process that is being dumped, specify
193 .I %p
194 in an argument.
195 .SS Controlling which mappings are written to the core dump
196 Since kernel 2.6.23, the Linux-specific
197 .IR /proc/PID/coredump_filter
198 file can be used to control which memory segments are written to the
199 core dump file in the event that a core dump is performed for the
200 process with the corresponding process ID.
201
202 The value in the file is a bit mask of memory mapping types (see
203 .BR mmap (2)).
204 If a bit is set in the mask, then memory mappings of the
205 corresponding type are dumped; otherwise they are not dumped.
206 The bits in this file have the following meanings:
207 .PP
208 .PD 0
209 .RS 4
210 .TP
211 bit 0
212 Dump anonymous private mappings.
213 .TP
214 bit 1
215 Dump anonymous shared mappings.
216 .TP
217 bit 2
218 Dump file-backed private mappings.
219 .TP
220 bit 3
221 Dump file-backed shared mappings.
222 .\" file-backed shared mappings of course also update the underlying
223 .\" mapped file.
224 .RE
225 .PD
226 .PP
227 The default value of
228 .I coredump_filter
229 is 0x3;
230 this reflects traditional Linux behavior and means that
231 only anonymous memory segments are dumped.
232
233 Memory-mapped I/O pages such as frame buffer are never dumped, and
234 virtual DSO pages are always dumped, regardless of the
235 .I coredump_filter
236 value.
237
238 A child process created via
239 .BR fork (2)
240 inherits its parents
241 .I coredump_filter
242 value;
243 the
244 .I coredump_filter
245 value is preserved across an
246 .BR execve (2).
247
248 It can be useful to set
249 .I coredump_filter
250 in the parent shell before running a program, for example:
251
252 .in +4n
253 .nf
254 .RB "$" " echo 0x7 > /proc/self/coredump_filter"
255 .RB "$" " ./some_program"
256 .fi
257 .in
258 .PP
259 This file is only provided if the kernel was built with the
260 .B CONFIG_ELF_CORE
261 configuration option.
262 .SH NOTES
263 The
264 .BR gdb (1)
265 .I gcore
266 command can be used to obtain a core dump of a running process.
267
268 If a multithreaded process (or, more precisely, a process that
269 shares its memory with another process by being created with the
270 .B CLONE_VM
271 flag of
272 .BR clone (2))
273 dumps core, then the process ID is always appended to the core filename,
274 unless the process ID was already included elsewhere in the
275 filename via a %p specification in
276 .IR /proc/sys/kernel/core_pattern .
277 (This is primarily useful when employing the LinuxThreads implementation,
278 where each thread of a process has a different PID.)
279 .\" Always including the PID in the name of the core file made
280 .\" sense for LinuxThreads, where each thread had a unique PID,
281 .\" but doesn't seem to serve any purpose with NPTL, where all the
282 .\" threads in a process share the same PID (as POSIX.1 requires).
283 .\" Probably the behavior is maintained so that applications using
284 .\" LinuxThreads continue appending the PID (the kernel has no easy
285 .\" way of telling which threading implementation the userspace
286 .\" application is using). -- mtk, April 2006
287 .SH EXAMPLE
288 The program below can be used to demonstrate the use of the
289 pipe syntax in the
290 .I /proc/sys/kernel/core_pattern
291 file.
292 The following shell session demonstrates the use of this program
293 (compiled to create an executable named
294 .IR core_pattern_pipe_test ):
295 .PP
296 .in +4n
297 .nf
298 .RB "$" " cc \-o core_pattern_pipe_test core_pattern_pipe_test.c"
299 .RB "$" " su"
300 Password:
301 .RB "#" " echo \(aq|$PWD/core_pattern_pipe_test %p \
302 UID=%u GID=%g sig=%s\(aq > \e"
303 .B " /proc/sys/kernel/core_pattern"
304 .RB "#" " exit"
305 .RB "$" " sleep 100"
306 .BR "^\e" " # type control-backslash"
307 Quit (core dumped)
308 .RB "$" " cat core.info"
309 argc=5
310 argc[0]=</home/mtk/core_pattern_pipe_test>
311 argc[1]=<20575>
312 argc[2]=<UID=1000>
313 argc[3]=<GID=100>
314 argc[4]=<sig=3>
315 Total bytes in core dump: 282624
316 .fi
317 .in
318 .SS Program source
319 .R " "
320 .nf
321 /* core_pattern_pipe_test.c */
322
323 #define _GNU_SOURCE
324 #include <sys/stat.h>
325 #include <fcntl.h>
326 #include <limits.h>
327 #include <stdio.h>
328 #include <stdlib.h>
329 #include <unistd.h>
330
331 #define BUF_SIZE 1024
332
333 int
334 main(int argc, char *argv[])
335 {
336 int tot, j;
337 ssize_t nread;
338 char buf[BUF_SIZE];
339 FILE *fp;
340 char cwd[PATH_MAX];
341
342 /* Change our current working directory to that of the
343 crashing process */
344
345 snprintf(cwd, PATH_MAX, "/proc/%s/cwd", argv[1]);
346 chdir(cwd);
347
348 /* Write output to file "core.info" in that directory */
349
350 fp = fopen("core.info", "w+");
351 if (fp == NULL)
352 exit(EXIT_FAILURE);
353
354 /* Display command\-line arguments given to core_pattern
355 pipe program */
356
357 fprintf(fp, "argc=%d\\n", argc);
358 for (j = 0; j < argc; j++)
359 fprintf(fp, "argc[%d]=<%s>\\n", j, argv[j]);
360
361 /* Count bytes in standard input (the core dump) */
362
363 tot = 0;
364 while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0)
365 tot += nread;
366 fprintf(fp, "Total bytes in core dump: %d\\n", tot);
367
368 exit(EXIT_SUCCESS);
369 }
370 .fi
371 .SH SEE ALSO
372 .BR bash (1),
373 .BR gdb (1),
374 .BR getrlimit (2),
375 .BR mmap (2),
376 .BR prctl (2),
377 .BR sigaction (2),
378 .BR elf (5),
379 .BR proc (5),
380 .BR pthreads (7),
381 .BR signal (7)