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

NOTES

306       The gdb(1) gcore command can be used to obtain a core dump of a running
307       process.
308
309       In  Linux  versions  up  to  and  including  2.6.27, if a multithreaded
310       process (or, more precisely, a process  that  shares  its  memory  with
311       another  process  by  being created with the CLONE_VM flag of clone(2))
312       dumps core, then the process ID is always appended to  the  core  file‐
313       name, unless the process ID was already included elsewhere in the file‐
314       name via a %p specification in /proc/sys/kernel/core_pattern.  (This is
315       primarily  useful  when employing the obsolete LinuxThreads implementa‐
316       tion, where each thread of a process has a different PID.)
317

EXAMPLE

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

SEE ALSO

396       bash(1),   coredumpctl(1),  gdb(1),  getrlimit(2),  mmap(2),  prctl(2),
397       sigaction(2), elf(5), proc(5),  pthreads(7),  signal(7),  systemd-core‐
398       dump(8)
399

COLOPHON

401       This  page  is  part of release 5.04 of the Linux man-pages project.  A
402       description of the project, information about reporting bugs,  and  the
403       latest     version     of     this    page,    can    be    found    at
404       https://www.kernel.org/doc/man-pages/.
405
406
407
408Linux                             2019-10-10                           CORE(5)
Impressum