1CORE(5)                    Linux Programmer's Manual                   CORE(5)
2
3
4

NAME

6       core - core dump file
7

DESCRIPTION

9       The  default  action of certain signals is to cause a process to termi‐
10       nate and produce a core dump file, a file containing an  image  of  the
11       process's memory at the time of termination.  This image can be used in
12       a debugger (e.g., gdb(1)) to inspect the state of the  program  at  the
13       time  that  it terminated.  A list of the signals which cause a process
14       to dump core can be found in signal(7).
15
16       A process can set its soft RLIMIT_CORE resource limit to place an upper
17       limit  on  the  size  of the core dump file that will be produced if it
18       receives a "core dump" signal; see getrlimit(2) for details.
19
20       There are various circumstances in which a core dump file is  not  pro‐
21       duced:
22
23       *  The  process  does  not have permission to write the core file.  (By
24          default, the core file is called core or core.pid, where pid is  the
25          ID  of  the  process that dumped core, and is created in the current
26          working directory.  See below for details on naming.)   Writing  the
27          core file fails if the directory in which it is to be created is not
28          writable, or if a file with the same name exists and is not writable
29          or  is  not  a  regular  file (e.g., it is a directory or a symbolic
30          link).
31
32       *  A (writable, regular) file with the same name as would be  used  for
33          the  core  dump already exists, but there is more than one hard link
34          to that file.
35
36       *  The filesystem where the core dump file would be created is full; or
37          has  run  out  of  inodes;  or is mounted read-only; or the user has
38          reached their quota for the filesystem.
39
40       *  The directory in which the core dump file is to be created does  not
41          exist.
42
43       *  The  RLIMIT_CORE  (core  file  size)  or  RLIMIT_FSIZE  (file  size)
44          resource limits for the process are set to  zero;  see  getrlimit(2)
45          and  the  documentation  of  the  shell's  ulimit  command (limit in
46          csh(1)).
47
48       *  The binary being executed by the process does not have read  permis‐
49          sion  enabled.   (This  is a security measure to ensure that an exe‐
50          cutable whose contents are not readable does not produce  a—possibly
51          readable—core dump containing an image of the executable.)
52
53       *  The  process  is executing a set-user-ID (set-group-ID) program that
54          is owned by a user (group) other than the real user  (group)  ID  of
55          the  process,  or  the  process is executing a program that has file
56          capabilities (see capabilities(7)).  (However, see  the  description
57          of  the  prctl(2)  PR_SET_DUMPABLE operation, and the description of
58          the /proc/sys/fs/suid_dumpable file in proc(5).)
59
60       *  /proc/sys/kernel/core_pattern   is    empty    and    /proc/sys/ker‐
61          nel/core_uses_pid  contains the value 0.  (These files are described
62          below.)  Note that if  /proc/sys/kernel/core_pattern  is  empty  and
63          /proc/sys/kernel/core_uses_pid contains the value 1, core dump files
64          will have names of the form .pid, and such files are  hidden  unless
65          one uses the ls(1) -a option.
66
67       *  (Since Linux 3.7) The kernel was configured without the CONFIG_CORE‐
68          DUMP option.
69
70       In addition, a core dump may exclude part of the address space  of  the
71       process if the madvise(2) MADV_DONTDUMP flag was employed.
72
73       On systems that employ systemd(1) as the init framework, core dumps may
74       instead be placed in a location determined by  systemd(1).   See  below
75       for further details.
76
77   Naming of core dump files
78       By  default,  a  core  dump  file is named core, but the /proc/sys/ker‐
79       nel/core_pattern file (since Linux 2.6 and 2.4.21) can be set to define
80       a template that is used to name core dump files.  The template can con‐
81       tain % specifiers which are substituted by the following values when  a
82       core file is created:
83
84           %%  A single % character.
85           %c  Core  file  size soft resource limit of crashing process (since
86               Linux 2.6.24).
87           %d  Dump mode—same as value returned  by  prctl(2)  PR_GET_DUMPABLE
88               (since Linux 3.7).
89           %e  The process or thread's comm value, which typically is the same
90               as the executable filename (without path prefix, and  truncated
91               to  a  maximum of 15 characters), but may have been modified to
92               be something different; see the discussion of  /proc/[pid]/comm
93               and /proc/[pid]/task/[tid]/comm in proc(5).
94           %E  Pathname of executable, with slashes ('/') replaced by exclama‐
95               tion marks ('!') (since Linux 3.0).
96           %g  Numeric real GID of dumped process.
97           %h  Hostname (same as nodename returned by uname(2)).
98           %i  TID of thread that triggered core dump,  as  seen  in  the  PID
99               namespace in which the thread resides (since Linux 3.18).
100           %I  TID  of thread that triggered core dump, as seen in the initial
101               PID namespace (since Linux 3.18).
102           %p  PID of dumped process, as seen in the PID  namespace  in  which
103               the process resides.
104           %P  PID  of  dumped  process,  as seen in the initial PID namespace
105               (since Linux 3.12).
106           %s  Number of signal causing dump.
107           %t  Time of dump, expressed as seconds since the Epoch,  1970-01-01
108               00:00:00 +0000 (UTC).
109           %u  Numeric real UID of dumped process.
110
111       A  single  %  at the end of the template is dropped from the core file‐
112       name, as is the combination of a % followed by any character other than
113       those listed above.  All other characters in the template become a lit‐
114       eral part of the core filename.  The template may include  '/'  charac‐
115       ters,  which  are  interpreted  as delimiters for directory names.  The
116       maximum size of the resulting core filename is 128 bytes (64  bytes  in
117       kernels before 2.6.19).  The default value in this file is "core".  For
118       backward  compatibility,  if  /proc/sys/kernel/core_pattern  does   not
119       include  %p  and /proc/sys/kernel/core_uses_pid (see below) is nonzero,
120       then .PID will be appended to the core filename.
121
122       Paths are interpreted according to the settings that are active for the
123       crashing  process.   That  means the crashing process's mount namespace
124       (see mount_namespaces(7)), its current  working  directory  (found  via
125       getcwd(2)), and its root directory (see chroot(2)).
126
127       Since  version  2.4, Linux has also provided a more primitive method of
128       controlling the name of the core  dump  file.   If  the  /proc/sys/ker‐
129       nel/core_uses_pid  file  contains the value 0, then a core dump file is
130       simply named core.  If this file contains a  nonzero  value,  then  the
131       core dump file includes the process ID in a name of the form core.PID.
132
133       Since  Linux  3.6,  if  /proc/sys/fs/suid_dumpable  is set to 2 ("suid‐
134       safe"), the pattern must be either an absolute pathname (starting  with
135       a leading '/' character) or a pipe, as defined below.
136
137   Piping core dumps to a program
138       Since  kernel  2.6.19,  Linux  supports  an  alternate  syntax  for the
139       /proc/sys/kernel/core_pattern file.  If the  first  character  of  this
140       file  is  a  pipe  symbol (|), then the remainder of the line is inter‐
141       preted as the command-line for a user-space program (or script) that is
142       to be executed.
143
144       Since  kernel 5.3.0, the pipe template is split on spaces into an argu‐
145       ment list before the template parameters are expanded.  In earlier ker‐
146       nels,  the  template  parameters  are  expanded first and the resulting
147       string is split on spaces into an argument list.  This  means  that  in
148       earlier kernels executable names added by the %e and %E template param‐
149       eters could get split into multiple arguments.  So the core  dump  han‐
150       dler  needs to put the executable names as the last argument and ensure
151       it joins all parts of the executable  name  using  spaces.   Executable
152       names  with  multiple  spaces  in them are not correctly represented in
153       earlier kernels, meaning that the core dump handler needs to use mecha‐
154       nisms to find the executable name.
155
156       Instead  of being written to a file, the core dump is given as standard
157       input to the program.  Note the following points:
158
159       *  The program must be specified using an absolute pathname (or a path‐
160          name relative to the root directory, /), and must immediately follow
161          the '|' character.
162
163       *  The command-line arguments can  include  any  of  the  %  specifiers
164          listed  above.   For example, to pass the PID of the process that is
165          being dumped, specify %p in an argument.
166
167       *  The process created to run the program runs as user and group root.
168
169       *  Running as root does not confer any exceptional  security  bypasses.
170          Namely,  LSMs  (e.g.,  SELinux) are still active and may prevent the
171          handler  from  accessing  details  about  the  crashed  process  via
172          /proc/[pid].
173
174       *  The  program  pathname  is  interpreted  with respect to the initial
175          mount namespace as it is always executed there.  It is not  affected
176          by  the  settings  (e.g.,  root  directory, mount namespace, current
177          working directory) of the crashing process.
178
179       *  The process runs in the initial namespaces (PID, mount, user, and so
180          on) and not in the namespaces of the crashing process.  One can uti‐
181          lize specifiers such as %P to find the right  /proc/[pid]  directory
182          and probe/enter the crashing process's namespaces if needed.
183
184       *  The  process  starts  with its current working directory as the root
185          directory.  If desired, it is possible change to the working  direc‐
186          tory  of  the dumping process by employing the value provided by the
187          %P specifier to change to the location of the  dumping  process  via
188          /proc/[pid]/cwd.
189
190       *  Command-line  arguments  can be supplied to the program (since Linux
191          2.6.24), delimited by white space (up to a total line length of  128
192          bytes).
193
194       *  The  RLIMIT_CORE limit is not enforced for core dumps that are piped
195          to a program via this mechanism.
196
197   /proc/sys/kernel/core_pipe_limit
198       When collecting core dumps via a pipe to a user-space program,  it  can
199       be  useful for the collecting program to gather data about the crashing
200       process from that process's /proc/[pid] directory.  In order to do this
201       safely,  the  kernel must wait for the program collecting the core dump
202       to exit, so as not to remove the crashing process's  /proc/[pid]  files
203       prematurely.   This  in turn creates the possibility that a misbehaving
204       collecting program can block the reaping of a crashed process by simply
205       never exiting.
206
207       Since Linux 2.6.32, the /proc/sys/kernel/core_pipe_limit can be used to
208       defend against this possibility.  The value in this  file  defines  how
209       many  concurrent crashing processes may be piped to user-space programs
210       in parallel.  If this value is exceeded, then those crashing  processes
211       above  this  value are noted in the kernel log and their core dumps are
212       skipped.
213
214       A value of 0 in this file is special.  It indicates that unlimited pro‐
215       cesses may be captured in parallel, but that no waiting will take place
216       (i.e., the collecting program is not guaranteed access to /proc/<crash‐
217       ing-PID>).  The default value for this file is 0.
218
219   Controlling which mappings are written to the core dump
220       Since  kernel  2.6.23,  the  Linux-specific /proc/[pid]/coredump_filter
221       file can be used to control which memory segments are  written  to  the
222       core  dump  file  in  the  event  that a core dump is performed for the
223       process with the corresponding process ID.
224
225       The value in the file is a  bit  mask  of  memory  mapping  types  (see
226       mmap(2)).   If  a  bit  is set in the mask, then memory mappings of the
227       corresponding type are dumped; otherwise they are not dumped.  The bits
228       in this file have the following meanings:
229
230           bit 0  Dump anonymous private mappings.
231           bit 1  Dump anonymous shared mappings.
232           bit 2  Dump file-backed private mappings.
233           bit 3  Dump file-backed shared mappings.
234           bit 4 (since Linux 2.6.24)
235                  Dump ELF headers.
236           bit 5 (since Linux 2.6.28)
237                  Dump private huge pages.
238           bit 6 (since Linux 2.6.28)
239                  Dump shared huge pages.
240           bit 7 (since Linux 4.4)
241                  Dump private DAX pages.
242           bit 8 (since Linux 4.4)
243                  Dump shared DAX pages.
244
245       By  default,  the  following  bits  are  set:  0,  1,  4  (if  the CON‐
246       FIG_CORE_DUMP_DEFAULT_ELF_HEADERS  kernel   configuration   option   is
247       enabled),  and  5.  This default can be modified at boot time using the
248       coredump_filter boot option.
249
250       The value of this file is displayed in hexadecimal.  (The default value
251       is thus displayed as 33.)
252
253       Memory-mapped I/O pages such as frame buffer are never dumped, and vir‐
254       tual DSO (vdso(7)) pages are always dumped,  regardless  of  the  core‐
255       dump_filter value.
256
257       A child process created via fork(2) inherits its parent's coredump_fil‐
258       ter value; the coredump_filter value is preserved across an execve(2).
259
260       It can be useful to set coredump_filter in the parent shell before run‐
261       ning a program, for example:
262
263           $ echo 0x7 > /proc/self/coredump_filter
264           $ ./some_program
265
266       This  file  is  provided  only  if  the  kernel was built with the CON‐
267       FIG_ELF_CORE configuration option.
268
269   Core dumps and systemd
270       On systems using the systemd(1)  init  framework,  core  dumps  may  be
271       placed  in a location determined by systemd(1).  To do this, systemd(1)
272       employs the core_pattern feature that allows piping  core  dumps  to  a
273       program.   One can verify this by checking whether core dumps are being
274       piped to the systemd-coredump(8) program:
275
276           $ cat /proc/sys/kernel/core_pattern
277           |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %e
278
279       In this case, core dumps will be placed in the location configured  for
280       systemd-coredump(8), typically as lz4(1) compressed files in the direc‐
281       tory /var/lib/systemd/coredump/.  One can list the core dumps that have
282       been recorded by systemd-coredump(8) using coredumpctl(1):
283
284         $ coredumpctl list | tail -5
285         Wed 2017-10-11 22:25:30 CEST  2748 1000 1000 3 present  /usr/bin/sleep
286         Thu 2017-10-12 06:29:10 CEST  2716 1000 1000 3 present  /usr/bin/sleep
287         Thu 2017-10-12 06:30:50 CEST  2767 1000 1000 3 present  /usr/bin/sleep
288         Thu 2017-10-12 06:37:40 CEST  2918 1000 1000 3 present  /usr/bin/cat
289         Thu 2017-10-12 08:13:07 CEST  2955 1000 1000 3 present  /usr/bin/cat
290
291       The  information shown for each core dump includes the date and time of
292       the dump, the PID, UID, and GID  of the  dumping  process,  the  signal
293       number  that  caused  the core dump, and the pathname of the executable
294       that was being run by the dumped process.   Various  options  to  core‐
295       dumpctl(1)  allow  a specified coredump file to be pulled from the sys‐
296       temd(1) location into a specified file.  For example,  to  extract  the
297       core  dump for PID 2955 shown above to a file named core in the current
298       directory, one could use:
299
300           $ coredumpctl dump 2955 -o core
301
302       For more extensive details, see the coredumpctl(1) manual page.
303
304       To (persistently) disable the systemd(1) mechanism that  archives  core
305       dumps, restoring to something more like traditional Linux behavior, one
306       can set an override for the systemd(1) mechanism, using something like:
307
308           # echo "kernel.core_pattern=core.%p" > \
309                          /etc/sysctl.d/50-coredump.conf
310           # /lib/systemd/systemd-sysctl
311
312       It is also possible to temporarily (i.e., until the next reboot) change
313       the  core_pattern  setting using a command such as the following (which
314       causes the names of core dump files to include the executable  name  as
315       well as the number of the signal which triggered the core dump):
316
317           # sysctl -w kernel.core_pattern="%e-%s.core"
318

NOTES

320       The gdb(1) gcore command can be used to obtain a core dump of a running
321       process.
322
323       In Linux versions up  to  and  including  2.6.27,  if  a  multithreaded
324       process  (or,  more  precisely,  a  process that shares its memory with
325       another process by being created with the CLONE_VM  flag  of  clone(2))
326       dumps  core,  then  the process ID is always appended to the core file‐
327       name, unless the process ID was already included elsewhere in the file‐
328       name via a %p specification in /proc/sys/kernel/core_pattern.  (This is
329       primarily useful when employing the obsolete  LinuxThreads  implementa‐
330       tion, where each thread of a process has a different PID.)
331

EXAMPLES

333       The program below can be used to demonstrate the use of the pipe syntax
334       in the /proc/sys/kernel/core_pattern file.  The following shell session
335       demonstrates  the use of this program (compiled to create an executable
336       named core_pattern_pipe_test):
337
338           $ cc -o core_pattern_pipe_test core_pattern_pipe_test.c
339           $ su
340           Password:
341           # echo "|$PWD/core_pattern_pipe_test %p UID=%u GID=%g sig=%s" > \
342               /proc/sys/kernel/core_pattern
343           # exit
344           $ sleep 100
345           ^\                     # type control-backslash
346           Quit (core dumped)
347           $ cat core.info
348           argc=5
349           argc[0]=</home/mtk/core_pattern_pipe_test>
350           argc[1]=<20575>
351           argc[2]=<UID=1000>
352           argc[3]=<GID=100>
353           argc[4]=<sig=3>
354           Total bytes in core dump: 282624
355
356   Program source
357
358       /* core_pattern_pipe_test.c */
359
360       #define _GNU_SOURCE
361       #include <sys/stat.h>
362       #include <fcntl.h>
363       #include <limits.h>
364       #include <stdio.h>
365       #include <stdlib.h>
366       #include <unistd.h>
367
368       #define BUF_SIZE 1024
369
370       int
371       main(int argc, char *argv[])
372       {
373           int tot, j;
374           ssize_t nread;
375           char buf[BUF_SIZE];
376           FILE *fp;
377           char cwd[PATH_MAX];
378
379           /* Change our current working directory to that of the
380              crashing process */
381
382           snprintf(cwd, PATH_MAX, "/proc/%s/cwd", argv[1]);
383           chdir(cwd);
384
385           /* Write output to file "core.info" in that directory */
386
387           fp = fopen("core.info", "w+");
388           if (fp == NULL)
389               exit(EXIT_FAILURE);
390
391           /* Display command-line arguments given to core_pattern
392              pipe program */
393
394           fprintf(fp, "argc=%d\n", argc);
395           for (j = 0; j < argc; j++)
396               fprintf(fp, "argc[%d]=<%s>\n", j, argv[j]);
397
398           /* Count bytes in standard input (the core dump) */
399
400           tot = 0;
401           while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0)
402               tot += nread;
403           fprintf(fp, "Total bytes in core dump: %d\n", tot);
404
405           fclose(fp);
406           exit(EXIT_SUCCESS);
407       }
408

SEE ALSO

410       bash(1),  coredumpctl(1),  gdb(1),  getrlimit(2),  mmap(2),   prctl(2),
411       sigaction(2),  elf(5),  proc(5),  pthreads(7), signal(7), systemd-core‐
412       dump(8)
413

COLOPHON

415       This page is part of release 5.07 of the Linux  man-pages  project.   A
416       description  of  the project, information about reporting bugs, and the
417       latest    version    of    this    page,    can     be     found     at
418       https://www.kernel.org/doc/man-pages/.
419
420
421
422Linux                             2020-06-09                           CORE(5)
Impressum