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