{
    "mode": "man",
    "parameter": "core",
    "section": "5",
    "url": "https://www.chedong.com/phpMan.php/man/core/5/json",
    "generated": "2026-10-04T15:38:14Z",
    "sections": {
        "NAME": {
            "content": "core - core dump file\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The  default  action of certain signals is to cause a process to terminate and produce a core\ndump file, a file containing an image of the process's memory at  the  time  of  termination.\nThis  image  can  be used in a debugger (e.g., gdb(1)) to inspect the state of the program at\nthe time that it terminated.  A list of the signals which cause a process to dump core can be\nfound in signal(7).\n\nA process can set its soft RLIMITCORE resource limit to place an upper limit on the size  of\nthe  core  dump  file  that  will  be produced if it receives a \"core dump\" signal; see getr‐\nlimit(2) for details.\n\nThere are various circumstances in which a core dump file is not produced:\n\n•  The process does not have permission to write the core file.  (By default, the  core  file\nis  called  core  or core.pid, where pid is the ID of the process that dumped core, and is\ncreated in the current working directory.  See below for details on naming.)  Writing  the\ncore  file  fails  if  the directory in which it is to be created is not writable, or if a\nfile with the same name exists and is not writable or is not a regular file (e.g., it is a\ndirectory or a symbolic link).\n\n•  A (writable, regular) file with the same name as would be used for the core  dump  already\nexists, but there is more than one hard link to that file.\n\n•  The  filesystem  where  the core dump file would be created is full; or has run out of in‐\nodes; or is mounted read-only; or the user has reached their quota for the filesystem.\n\n•  The directory in which the core dump file is to be created does not exist.\n\n•  The RLIMITCORE (core file size) or RLIMITFSIZE  (file  size)  resource  limits  for  the\nprocess are set to zero; see getrlimit(2) and the documentation of the shell's ulimit com‐\nmand  (limit in csh(1)).  However, RLIMITCORE will be ignored if the system is configured\nto pipe core dumps to a program.\n\n•  The binary being executed by the process does not have read permission enabled.  (This  is\na  security  measure to ensure that an executable whose contents are not readable does not\nproduce a—possibly readable—core dump containing an image of the executable.)\n\n•  The process is executing a set-user-ID (set-group-ID) program that  is  owned  by  a  user\n(group)  other than the real user (group) ID of the process, or the process is executing a\nprogram that has file capabilities (see capabilities(7)).  (However, see  the  description\nof    the    prctl(2)    PRSETDUMPABLE   operation,   and   the   description   of   the\n/proc/sys/fs/suiddumpable file in proc(5).)\n\n•  /proc/sys/kernel/corepattern is empty  and  /proc/sys/kernel/coreusespid  contains  the\nvalue  0.   (These files are described below.)  Note that if /proc/sys/kernel/corepattern\nis empty and /proc/sys/kernel/coreusespid contains the value 1,  core  dump  files  will\nhave  names  of  the form .pid, and such files are hidden unless one uses the ls(1) -a op‐\ntion.\n\n•  (Since Linux 3.7) The kernel was configured without the CONFIGCOREDUMP option.\n\nIn addition, a core dump may exclude part of the address space of the  process  if  the  mad‐\nvise(2) MADVDONTDUMP flag was employed.\n\nOn  systems that employ systemd(1) as the init framework, core dumps may instead be placed in\na location determined by systemd(1).  See below for further details.\n",
            "subsections": [
                {
                    "name": "Naming of core dump files",
                    "content": "By default, a core dump file is named core, but the /proc/sys/kernel/corepattern file (since\nLinux 2.6 and 2.4.21) can be set to define a template that is used to name core  dump  files.\nThe  template  can  contain % specifiers which are substituted by the following values when a\ncore file is created:\n\n%%  A single % character.\n%c  Core file size soft resource limit of crashing process (since Linux 2.6.24).\n%d  Dump mode—same as value returned by prctl(2) PRGETDUMPABLE (since Linux 3.7).\n%e  The process or thread's comm value, which typically is the  same  as  the  executable\nfilename  (without path prefix, and truncated to a maximum of 15 characters), but may\nhave been modified to be something different; see the  discussion  of  /proc/pid/comm\nand /proc/pid/task/tid/comm in proc(5).\n%E  Pathname of executable, with slashes ('/') replaced by exclamation marks ('!') (since\nLinux 3.0).\n%g  Numeric real GID of dumped process.\n%h  Hostname (same as nodename returned by uname(2)).\n%i  TID  of  thread  that  triggered core dump, as seen in the PID namespace in which the\nthread resides (since Linux 3.18).\n%I  TID of thread that triggered core dump, as seen in the initial PID  namespace  (since\nLinux 3.18).\n%p  PID of dumped process, as seen in the PID namespace in which the process resides.\n%P  PID of dumped process, as seen in the initial PID namespace (since Linux 3.12).\n%s  Number of signal causing dump.\n%t  Time of dump, expressed as seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).\n%u  Numeric real UID of dumped process.\n\nA  single  % at the end of the template is dropped from the core filename, as is the combina‐\ntion of a % followed by any character other than those listed above.  All other characters in\nthe template become a literal part of the core filename.  The template may include '/'  char‐\nacters, which are interpreted as delimiters for directory names.  The maximum size of the re‐\nsulting core filename is 128 bytes (64 bytes before Linux 2.6.19).  The default value in this\nfile  is  \"core\".   For backward compatibility, if /proc/sys/kernel/corepattern does not in‐\nclude %p and /proc/sys/kernel/coreusespid (see below) is nonzero, then  .PID  will  be  ap‐\npended to the core filename.\n\nPaths  are  interpreted  according  to the settings that are active for the crashing process.\nThat means the crashing process's mount  namespace  (see  mountnamespaces(7)),  its  current\nworking directory (found via getcwd(2)), and its root directory (see chroot(2)).\n\nSince  Linux  2.4, Linux has also provided a more primitive method of controlling the name of\nthe core dump file.  If the /proc/sys/kernel/coreusespid file contains the value 0, then  a\ncore  dump  file  is simply named core.  If this file contains a nonzero value, then the core\ndump file includes the process ID in a name of the form core.PID.\n\nSince Linux 3.6, if /proc/sys/fs/suiddumpable is set to 2 (\"suidsafe\"), the pattern must  be\neither an absolute pathname (starting with a leading '/' character) or a pipe, as defined be‐\nlow.\n"
                },
                {
                    "name": "Piping core dumps to a program",
                    "content": "Since  Linux 2.6.19, Linux supports an alternate syntax for the /proc/sys/kernel/corepattern\nfile.  If the first character of this file is a pipe symbol (|), then the  remainder  of  the\nline  is  interpreted  as the command-line for a user-space program (or script) that is to be\nexecuted.\n\nSince Linux 5.3.0, the pipe template is split on spaces into an argument list before the tem‐\nplate parameters are expanded.  In earlier kernels,  the  template  parameters  are  expanded\nfirst  and the resulting string is split on spaces into an argument list.  This means that in\nearlier kernels executable names added by the %e and %E template parameters could  get  split\ninto  multiple  arguments.  So the core dump handler needs to put the executable names as the\nlast argument and ensure it joins all parts of the executable name using spaces.   Executable\nnames  with multiple spaces in them are not correctly represented in earlier kernels, meaning\nthat the core dump handler needs to use mechanisms to find the executable name.\n\nInstead of being written to a file, the core dump is given as standard input to the  program.\nNote the following points:\n\n•  The  program  must  be specified using an absolute pathname (or a pathname relative to the\nroot directory, /), and must immediately follow the '|' character.\n\n•  The command-line arguments can include any of the % specifiers listed above.  For example,\nto pass the PID of the process that is being dumped, specify %p in an argument.\n\n•  The process created to run the program runs as user and group root.\n\n•  Running as root does not confer any exceptional security bypasses.   Namely,  LSMs  (e.g.,\nSELinux)  are  still  active  and may prevent the handler from accessing details about the\ncrashed process via /proc/pid.\n\n•  The program pathname is interpreted with respect to the initial mount namespace as  it  is\nalways  executed  there.   It is not affected by the settings (e.g., root directory, mount\nnamespace, current working directory) of the crashing process.\n\n•  The process runs in the initial namespaces (PID, mount, user, and so on) and  not  in  the\nnamespaces  of  the  crashing  process.  One can utilize specifiers such as %P to find the\nright /proc/pid directory and probe/enter the crashing process's namespaces if needed.\n\n•  The process starts with its current working directory as the root directory.  If  desired,\nit  is  possible  change  to the working directory of the dumping process by employing the\nvalue provided by the %P specifier to change to the location of the  dumping  process  via\n/proc/pid/cwd.\n\n•  Command-line  arguments  can be supplied to the program (since Linux 2.6.24), delimited by\nwhite space (up to a total line length of 128 bytes).\n\n•  The RLIMITCORE limit is not enforced for core dumps that are piped to a program via  this\nmechanism.\n"
                },
                {
                    "name": "/proc/sys/kernel/core_pipe_limit",
                    "content": "When  collecting core dumps via a pipe to a user-space program, it can be useful for the col‐\nlecting program to gather data about the crashing process from that process's  /proc/pid  di‐\nrectory.   In  order  to  do this safely, the kernel must wait for the program collecting the\ncore dump to exit, so as not to remove the crashing process's  /proc/pid  files  prematurely.\nThis  in  turn  creates  the  possibility that a misbehaving collecting program can block the\nreaping of a crashed process by simply never exiting.\n\nSince Linux 2.6.32, the /proc/sys/kernel/corepipelimit can be used to defend  against  this\npossibility.   The  value  in this file defines how many concurrent crashing processes may be\npiped to user-space programs in parallel.  If this value is  exceeded,  then  those  crashing\nprocesses above this value are noted in the kernel log and their core dumps are skipped.\n\nA  value of 0 in this file is special.  It indicates that unlimited processes may be captured\nin parallel, but that no waiting will take place (i.e., the collecting program is not guaran‐\nteed access to /proc/<crashing-PID>).  The default value for this file is 0.\n"
                },
                {
                    "name": "Controlling which mappings are written to the core dump",
                    "content": "Since Linux 2.6.23, the Linux-specific /proc/pid/coredumpfilter file can be used to  control\nwhich memory segments are written to the core dump file in the event that a core dump is per‐\nformed for the process with the corresponding process ID.\n\nThe  value  in the file is a bit mask of memory mapping types (see mmap(2)).  If a bit is set\nin the mask, then memory mappings of the corresponding type are dumped;  otherwise  they  are\nnot dumped.  The bits in this file have the following meanings:\n\nbit 0  Dump anonymous private mappings.\nbit 1  Dump anonymous shared mappings.\nbit 2  Dump file-backed private mappings.\nbit 3  Dump file-backed shared mappings.\nbit 4 (since Linux 2.6.24)\nDump ELF headers.\nbit 5 (since Linux 2.6.28)\nDump private huge pages.\nbit 6 (since Linux 2.6.28)\nDump shared huge pages.\nbit 7 (since Linux 4.4)\nDump private DAX pages.\nbit 8 (since Linux 4.4)\nDump shared DAX pages.\n\nBy  default, the following bits are set: 0, 1, 4 (if the CONFIGCOREDUMPDEFAULTELFHEADERS\nkernel configuration option is enabled), and 5.  This default can be modified  at  boot  time\nusing the coredumpfilter boot option.\n\nThe  value of this file is displayed in hexadecimal.  (The default value is thus displayed as\n33.)\n\nMemory-mapped I/O pages such as frame buffer are never  dumped,  and  virtual  DSO  (vdso(7))\npages are always dumped, regardless of the coredumpfilter value.\n\nA  child  process  created via fork(2) inherits its parent's coredumpfilter value; the core‐\ndumpfilter value is preserved across an execve(2).\n\nIt can be useful to set coredumpfilter in the parent shell before running a program, for ex‐\nample:\n\n$ echo 0x7 > /proc/self/coredumpfilter\n$ ./someprogram\n\nThis file is provided only if the kernel was built with the CONFIGELFCORE configuration op‐\ntion.\n"
                },
                {
                    "name": "Core dumps and systemd",
                    "content": "On systems using the systemd(1) init framework, core dumps may be placed in a location deter‐\nmined by systemd(1).  To do this, systemd(1) employs the  corepattern  feature  that  allows\npiping core dumps to a program.  One can verify this by checking whether core dumps are being\npiped to the systemd-coredump(8) program:\n\n$ cat /proc/sys/kernel/corepattern\n|/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %e\n\nIn  this  case, core dumps will be placed in the location configured for systemd-coredump(8),\ntypically as lz4(1) compressed files in the directory  /var/lib/systemd/coredump/.   One  can\nlist the core dumps that have been recorded by systemd-coredump(8) using coredumpctl(1):\n\n$ coredumpctl list | tail -5\nWed 2017-10-11 22:25:30 CEST  2748 1000 1000 3 present  /usr/bin/sleep\nThu 2017-10-12 06:29:10 CEST  2716 1000 1000 3 present  /usr/bin/sleep\nThu 2017-10-12 06:30:50 CEST  2767 1000 1000 3 present  /usr/bin/sleep\nThu 2017-10-12 06:37:40 CEST  2918 1000 1000 3 present  /usr/bin/cat\nThu 2017-10-12 08:13:07 CEST  2955 1000 1000 3 present  /usr/bin/cat\n\nThe  information  shown  for  each core dump includes the date and time of the dump, the PID,\nUID, and GID  of the dumping process, the signal number that caused the core  dump,  and  the\npathname  of  the  executable  that  was being run by the dumped process.  Various options to\ncoredumpctl(1) allow a specified coredump file to be pulled from the systemd(1) location into\na specified file.  For example, to extract the core dump for PID 2955 shown above to  a  file\nnamed core in the current directory, one could use:\n\n$ coredumpctl dump 2955 -o core\n\nFor more extensive details, see the coredumpctl(1) manual page.\n\nTo  (persistently)  disable  the  systemd(1) mechanism that archives core dumps, restoring to\nsomething more like traditional Linux behavior, one can set an override  for  the  systemd(1)\nmechanism, using something like:\n\n# echo \"kernel.corepattern=core.%p\" > \\\n/etc/sysctl.d/50-coredump.conf\n# /lib/systemd/systemd-sysctl\n\nIt is also possible to temporarily (i.e., until the next reboot) change the corepattern set‐\nting  using a command such as the following (which causes the names of core dump files to in‐\nclude the executable name as well as the number of the signal which triggered the core dump):\n\n# sysctl -w kernel.corepattern=\"%e-%s.core\"\n"
                }
            ]
        },
        "NOTES": {
            "content": "The gdb(1) gcore command can be used to obtain a core dump of a running process.\n\nIn Linux versions up to and including 2.6.27, if a multithreaded process (or, more precisely,\na process that shares its memory with another process by being created with the CLONEVM flag\nof clone(2)) dumps core, then the process ID is always appended to the core filename,  unless\nthe  process  ID  was  already  included  elsewhere in the filename via a %p specification in\n/proc/sys/kernel/corepattern.  (This is primarily useful when employing the obsolete  Linux‐\nThreads implementation, where each thread of a process has a different PID.)\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "The program below can be used to demonstrate the use of the pipe syntax in the /proc/sys/ker‐\nnel/corepattern  file.   The  following  shell  session demonstrates the use of this program\n(compiled to create an executable named corepatternpipetest):\n\n$ cc -o corepatternpipetest corepatternpipetest.c\n$ su\nPassword:\n# echo \"|$PWD/corepatternpipetest %p UID=%u GID=%g sig=%s\" > \\\n/proc/sys/kernel/corepattern\n# exit\n$ sleep 100\n^\\                     # type control-backslash\nQuit (core dumped)\n$ cat core.info\nargc=5\nargc[0]=</home/mtk/corepatternpipetest>\nargc[1]=<20575>\nargc[2]=<UID=1000>\nargc[3]=<GID=100>\nargc[4]=<sig=3>\nTotal bytes in core dump: 282624\n",
            "subsections": [
                {
                    "name": "Program source",
                    "content": "/* corepatternpipetest.c */\n\n#define GNUSOURCE\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <limits.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <unistd.h>\n\n#define BUFSIZE 1024\n\nint\nmain(int argc, char *argv[])\n{\nssizet nread, tot;\nchar buf[BUFSIZE];\nFILE *fp;\nchar cwd[PATHMAX];\n\n/* Change our current working directory to that of the\ncrashing process. */\n\nsnprintf(cwd, PATHMAX, \"/proc/%s/cwd\", argv[1]);\nchdir(cwd);\n\n/* Write output to file \"core.info\" in that directory. */\n\nfp = fopen(\"core.info\", \"w+\");\nif (fp == NULL)\nexit(EXITFAILURE);\n\n/* Display command-line arguments given to corepattern\npipe program. */\n\nfprintf(fp, \"argc=%d\\n\", argc);\nfor (sizet j = 0; j < argc; j++)\nfprintf(fp, \"argc[%zu]=<%s>\\n\", j, argv[j]);\n\n/* Count bytes in standard input (the core dump). */\n\ntot = 0;\nwhile ((nread = read(STDINFILENO, buf, BUFSIZE)) > 0)\ntot += nread;\nfprintf(fp, \"Total bytes in core dump: %zd\\n\", tot);\n\nfclose(fp);\nexit(EXITSUCCESS);\n}\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "bash(1), coredumpctl(1),  gdb(1),  getrlimit(2),  mmap(2),  prctl(2),  sigaction(2),  elf(5),\nproc(5), pthreads(7), signal(7), systemd-coredump(8)\n\nLinux man-pages 6.7                          2023-10-31                                      core(5)",
            "subsections": []
        }
    },
    "summary": "core - core dump file",
    "flags": [],
    "examples": [
        "The program below can be used to demonstrate the use of the pipe syntax in the /proc/sys/ker‐",
        "nel/corepattern  file.   The  following  shell  session demonstrates the use of this program",
        "(compiled to create an executable named corepatternpipetest):",
        "$ cc -o corepatternpipetest corepatternpipetest.c",
        "$ su",
        "Password:",
        "# echo \"|$PWD/corepatternpipetest %p UID=%u GID=%g sig=%s\" > \\",
        "/proc/sys/kernel/corepattern",
        "# exit",
        "$ sleep 100",
        "^\\                     # type control-backslash",
        "Quit (core dumped)",
        "$ cat core.info",
        "argc=5",
        "argc[0]=</home/mtk/corepatternpipetest>",
        "argc[1]=<20575>",
        "argc[2]=<UID=1000>",
        "argc[3]=<GID=100>",
        "argc[4]=<sig=3>",
        "Total bytes in core dump: 282624",
        "/* corepatternpipetest.c */",
        "#define GNUSOURCE",
        "#include <sys/stat.h>",
        "#include <fcntl.h>",
        "#include <limits.h>",
        "#include <stdio.h>",
        "#include <stdlib.h>",
        "#include <unistd.h>",
        "#define BUFSIZE 1024",
        "int",
        "main(int argc, char *argv[])",
        "ssizet nread, tot;",
        "char buf[BUFSIZE];",
        "FILE *fp;",
        "char cwd[PATHMAX];",
        "/* Change our current working directory to that of the",
        "crashing process. */",
        "snprintf(cwd, PATHMAX, \"/proc/%s/cwd\", argv[1]);",
        "chdir(cwd);",
        "/* Write output to file \"core.info\" in that directory. */",
        "fp = fopen(\"core.info\", \"w+\");",
        "if (fp == NULL)",
        "exit(EXITFAILURE);",
        "/* Display command-line arguments given to corepattern",
        "pipe program. */",
        "fprintf(fp, \"argc=%d\\n\", argc);",
        "for (sizet j = 0; j < argc; j++)",
        "fprintf(fp, \"argc[%zu]=<%s>\\n\", j, argv[j]);",
        "/* Count bytes in standard input (the core dump). */",
        "tot = 0;",
        "while ((nread = read(STDINFILENO, buf, BUFSIZE)) > 0)",
        "tot += nread;",
        "fprintf(fp, \"Total bytes in core dump: %zd\\n\", tot);",
        "fclose(fp);",
        "exit(EXITSUCCESS);"
    ],
    "see_also": [
        {
            "name": "bash",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/bash/1/json"
        },
        {
            "name": "coredumpctl",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/coredumpctl/1/json"
        },
        {
            "name": "gdb",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/gdb/1/json"
        },
        {
            "name": "getrlimit",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/getrlimit/2/json"
        },
        {
            "name": "mmap",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/mmap/2/json"
        },
        {
            "name": "prctl",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/prctl/2/json"
        },
        {
            "name": "sigaction",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/sigaction/2/json"
        },
        {
            "name": "elf",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/elf/5/json"
        },
        {
            "name": "proc",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/proc/5/json"
        },
        {
            "name": "pthreads",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/pthreads/7/json"
        },
        {
            "name": "signal",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/signal/7/json"
        },
        {
            "name": "systemd-coredump",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/systemd-coredump/8/json"
        }
    ]
}