OSDN Git Service

Update README
[linuxjm/LDP_man-pages.git] / original / 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 2014-08-19 "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
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
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 (However, see the description of the
98 .BR prctl (2)
99 .B PR_SET_DUMPABLE
100 operation, and the description of the
101 .I /proc/sys/fs/suid_dumpable
102 .\" FIXME . Perhaps relocate discussion of /proc/sys/fs/suid_dumpable
103 .\" and PR_SET_DUMPABLE to this page?
104 file in
105 .BR proc (5).)
106 .IP *
107 (Since Linux 3.7)
108 .\" commit 046d662f481830e652ac34cd112249adde16452a
109 The kernel was configured without the
110 .BR CONFIG_COREDUMP
111 option.
112 .PP
113 In addition,
114 a core dump may exclude part of the address space of the process if the
115 .BR madvise (2)
116 .B MADV_DONTDUMP
117 flag was employed.
118 .SS Naming of core dump files
119 By default, a core dump file is named
120 .IR core ,
121 but the
122 .I /proc/sys/kernel/core_pattern
123 file (since Linux 2.6 and 2.4.21)
124 can be set to define a template that is used to name core dump files.
125 The template can contain % specifiers which are substituted
126 by the following values when a core file is created:
127 .PP
128 .RS 4
129 .PD 0
130 .TP 4
131 %%
132 a single % character
133 .TP
134 %c
135 core file size soft resource limit of crashing process (since Linux 2.6.24)
136 .TP
137 %d
138 .\" Added in git commit 12a2b4b2241e318b4f6df31228e4272d2c2968a1
139 dump mode\(emsame as value returned by
140 .BR prctl (2)
141 .B PR_GET_DUMPABLE
142 (since Linux 3.7)
143 .TP
144 %e
145 executable filename (without path prefix)
146 .TP
147 %E
148 pathname of executable,
149 with slashes (\(aq/\(aq) replaced by exclamation marks (\(aq!\(aq)
150 (since Linux 3.0).
151 .TP
152 %g
153 (numeric) real GID of dumped process
154 .TP
155 %h
156 hostname (same as \fInodename\fP returned by \fBuname\fP(2))
157 .TP
158 %p
159 PID of dumped process,
160 as seen in the PID namespace in which the process resides
161 .TP
162 %P
163 .\" Added in git commit 65aafb1e7484b7434a0c1d4c593191ebe5776a2f
164 PID of dumped process, as seen in the initial PID namespace
165 (since Linux 3.12)
166 .TP
167 %s
168 number of signal causing dump
169 .TP
170 %t
171 time of dump, expressed as seconds since the
172 Epoch, 1970-01-01 00:00:00 +0000 (UTC)
173 .TP
174 %u
175 (numeric) real UID of dumped process
176 .PD
177 .RE
178 .PP
179 A single % at the end of the template is dropped from the
180 core filename, as is the combination of a % followed by any
181 character other than those listed above.
182 All other characters in the template become a literal
183 part of the core filename.
184 The template may include \(aq/\(aq characters, which are interpreted
185 as delimiters for directory names.
186 The maximum size of the resulting core filename is 128 bytes (64 bytes
187 in kernels before 2.6.19).
188 The default value in this file is "core".
189 For backward compatibility, if
190 .I /proc/sys/kernel/core_pattern
191 does not include "%p" and
192 .I /proc/sys/kernel/core_uses_pid
193 (see below)
194 is nonzero, then .PID will be appended to the core filename.
195
196 Since version 2.4, Linux has also provided
197 a more primitive method of controlling
198 the name of the core dump file.
199 If the
200 .I /proc/sys/kernel/core_uses_pid
201 file contains the value 0, then a core dump file is simply named
202 .IR core .
203 If this file contains a nonzero value, then the core dump file includes
204 the process ID in a name of the form
205 .IR core.PID .
206
207 Since Linux 3.6,
208 .\" 9520628e8ceb69fa9a4aee6b57f22675d9e1b709
209 if
210 .I /proc/sys/fs/suid_dumpable
211 is set to 2 ("suidsafe"), the pattern must be either an absolute pathname
212 (starting with a leading \(aq/\(aq character) or a pipe, as defined below.
213 .SS Piping core dumps to a program
214 Since kernel 2.6.19, Linux supports an alternate syntax for the
215 .I /proc/sys/kernel/core_pattern
216 file.
217 If the first character of this file is a pipe symbol (\fB|\fP),
218 then the remainder of the line is interpreted as a program to be
219 executed.
220 Instead of being written to a disk file, the core dump is given as
221 standard input to the program.
222 Note the following points:
223 .IP * 3
224 The program must be specified using an absolute pathname (or a
225 pathname relative to the root directory, \fI/\fP),
226 and must immediately follow the '|' character.
227 .IP *
228 The process created to run the program runs as user and group
229 .IR root .
230 .IP *
231 Command-line arguments can be supplied to the
232 program (since Linux 2.6.24),
233 delimited by white space (up to a total line length of 128 bytes).
234 .IP *
235 The command-line arguments can include any of
236 the % specifiers listed above.
237 For example, to pass the PID of the process that is being dumped, specify
238 .I %p
239 in an argument.
240 .SS Controlling which mappings are written to the core dump
241 Since kernel 2.6.23, the Linux-specific
242 .IR /proc/PID/coredump_filter
243 file can be used to control which memory segments are written to the
244 core dump file in the event that a core dump is performed for the
245 process with the corresponding process ID.
246
247 The value in the file is a bit mask of memory mapping types (see
248 .BR mmap (2)).
249 If a bit is set in the mask, then memory mappings of the
250 corresponding type are dumped; otherwise they are not dumped.
251 The bits in this file have the following meanings:
252 .PP
253 .PD 0
254 .RS 4
255 .TP
256 bit 0
257 Dump anonymous private mappings.
258 .TP
259 bit 1
260 Dump anonymous shared mappings.
261 .TP
262 bit 2
263 Dump file-backed private mappings.
264 .TP
265 bit 3
266 Dump file-backed shared mappings.
267 .\" file-backed shared mappings of course also update the underlying
268 .\" mapped file.
269 .TP
270 bit 4 (since Linux 2.6.24)
271 Dump ELF headers.
272 .TP
273 bit 5 (since Linux 2.6.28)
274 Dump private huge pages.
275 .TP
276 bit 6 (since Linux 2.6.28)
277 Dump shared huge pages.
278 .RE
279 .PD
280 .PP
281 By default, the following bits are set: 0, 1, 4 (if the
282 .B CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS
283 kernel configuration option is enabled), and 5.
284 The value of this file is displayed in hexadecimal.
285 (The default value is thus displayed as 33.)
286
287 Memory-mapped I/O pages such as frame buffer are never dumped, and
288 virtual DSO pages are always dumped, regardless of the
289 .I coredump_filter
290 value.
291
292 A child process created via
293 .BR fork (2)
294 inherits its parent's
295 .I coredump_filter
296 value;
297 the
298 .I coredump_filter
299 value is preserved across an
300 .BR execve (2).
301
302 It can be useful to set
303 .I coredump_filter
304 in the parent shell before running a program, for example:
305
306 .in +4n
307 .nf
308 .RB "$" " echo 0x7 > /proc/self/coredump_filter"
309 .RB "$" " ./some_program"
310 .fi
311 .in
312 .PP
313 This file is provided only if the kernel was built with the
314 .B CONFIG_ELF_CORE
315 configuration option.
316 .SH NOTES
317 The
318 .BR gdb (1)
319 .I gcore
320 command can be used to obtain a core dump of a running process.
321
322 In Linux versions up to and including 2.6.27,
323 .\" Changed with commit 6409324b385f3f63a03645b4422e3be67348d922
324 if a multithreaded process (or, more precisely, a process that
325 shares its memory with another process by being created with the
326 .B CLONE_VM
327 flag of
328 .BR clone (2))
329 dumps core, then the process ID is always appended to the core filename,
330 unless the process ID was already included elsewhere in the
331 filename via a %p specification in
332 .IR /proc/sys/kernel/core_pattern .
333 (This is primarily useful when employing the obsolete
334 LinuxThreads implementation,
335 where each thread of a process has a different PID.)
336 .\" Always including the PID in the name of the core file made
337 .\" sense for LinuxThreads, where each thread had a unique PID,
338 .\" but doesn't seem to serve any purpose with NPTL, where all the
339 .\" threads in a process share the same PID (as POSIX.1 requires).
340 .\" Probably the behavior is maintained so that applications using
341 .\" LinuxThreads continue appending the PID (the kernel has no easy
342 .\" way of telling which threading implementation the user-space
343 .\" application is using). -- mtk, April 2006
344 .SH EXAMPLE
345 The program below can be used to demonstrate the use of the
346 pipe syntax in the
347 .I /proc/sys/kernel/core_pattern
348 file.
349 The following shell session demonstrates the use of this program
350 (compiled to create an executable named
351 .IR core_pattern_pipe_test ):
352 .PP
353 .in +4n
354 .nf
355 .RB "$" " cc \-o core_pattern_pipe_test core_pattern_pipe_test.c"
356 .RB "$" " su"
357 Password:
358 .RB "#" " echo \(dq|$PWD/core_pattern_pipe_test %p \
359 UID=%u GID=%g sig=%s\(dq > \e"
360 .B "    /proc/sys/kernel/core_pattern"
361 .RB "#" " exit"
362 .RB "$" " sleep 100"
363 .BR "^\e" "                     # type control-backslash"
364 Quit (core dumped)
365 .RB "$" " cat core.info"
366 argc=5
367 argc[0]=</home/mtk/core_pattern_pipe_test>
368 argc[1]=<20575>
369 argc[2]=<UID=1000>
370 argc[3]=<GID=100>
371 argc[4]=<sig=3>
372 Total bytes in core dump: 282624
373 .fi
374 .in
375 .SS Program source
376 \&
377 .nf
378 /* core_pattern_pipe_test.c */
379
380 #define _GNU_SOURCE
381 #include <sys/stat.h>
382 #include <fcntl.h>
383 #include <limits.h>
384 #include <stdio.h>
385 #include <stdlib.h>
386 #include <unistd.h>
387
388 #define BUF_SIZE 1024
389
390 int
391 main(int argc, char *argv[])
392 {
393     int tot, j;
394     ssize_t nread;
395     char buf[BUF_SIZE];
396     FILE *fp;
397     char cwd[PATH_MAX];
398
399     /* Change our current working directory to that of the
400        crashing process */
401
402     snprintf(cwd, PATH_MAX, "/proc/%s/cwd", argv[1]);
403     chdir(cwd);
404
405     /* Write output to file "core.info" in that directory */
406
407     fp = fopen("core.info", "w+");
408     if (fp == NULL)
409         exit(EXIT_FAILURE);
410
411     /* Display command\-line arguments given to core_pattern
412        pipe program */
413
414     fprintf(fp, "argc=%d\\n", argc);
415     for (j = 0; j < argc; j++)
416         fprintf(fp, "argc[%d]=<%s>\\n", j, argv[j]);
417
418     /* Count bytes in standard input (the core dump) */
419
420     tot = 0;
421     while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0)
422         tot += nread;
423     fprintf(fp, "Total bytes in core dump: %d\\n", tot);
424
425     fclose(fp);
426     exit(EXIT_SUCCESS);
427 }
428 .fi
429 .SH SEE ALSO
430 .BR bash (1),
431 .BR gdb (1),
432 .BR getrlimit (2),
433 .BR mmap (2),
434 .BR prctl (2),
435 .BR sigaction (2),
436 .BR elf (5),
437 .BR proc (5),
438 .BR pthreads (7),
439 .BR signal (7)
440 .SH COLOPHON
441 This page is part of release 3.79 of the Linux
442 .I man-pages
443 project.
444 A description of the project,
445 information about reporting bugs,
446 and the latest version of this page,
447 can be found at
448 \%http://www.kernel.org/doc/man\-pages/.