OSDN Git Service

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