# info > CORE

---
type: CommandReference
command: CORE
mode: perldoc
section: 3perl
source: perldoc
---

## Quick Reference

- `CORE::function` — forces use of built-in Perl function, even if overridden
- `use subs 'function'` — override a built-in in a single package
- `*CORE::GLOBAL::function = sub { ... }` — globally override a built-in
- `\&CORE::function` — take reference to a built-in (many functions, but not all)
- Cannot use ampersand syntax or references for functions with special syntax: `chdir`, `chomp`, `chop`, `defined`, `delete`, `eof`, `exec`, `exists`, `lstat`, `split`, `stat`, `system`, `truncate`, `unlink`

## Name

CORE - Namespace for Perl's core routines

## Synopsis

perl
BEGIN {
    *CORE::GLOBAL::hex = sub { 1; };
}
print hex("0x50"),"\n";                     # prints 1
print CORE::hex("0x50"),"\n";               # prints 80
CORE::say "yes";                            # prints yes

BEGIN { *shove = \&CORE::push; }
shove @array, 1,2,3;                        # pushes on to @array
## Description

The `CORE` namespace provides access to Perl's built-in functions. The `CORE` package is built into Perl; no `use` or `require` is needed. For all Perl keywords, a `CORE::` prefix forces the built-in function, even if overridden or requiring a feature pragma. This is a syntactic feature, not related to the package.

For many Perl functions (since 5.16), the `CORE` package contains real subroutines. You can take references to these and make aliases. However, some can only be called as barewords (no ampersand syntax or references). The following keywords do **not** have real subroutines in CORE:

`__DATA__`, `__END__`, `and`, `cmp`, `default`, `do`, `dump`, `else`, `elsif`, `eq`, `eval`, `for`, `foreach`, `format`, `ge`, `given`, `goto`, `grep`, `gt`, `if`, `last`, `le`, `local`, `lt`, `m`, `map`, `my`, `ne`, `next`, `no`, `or`, `our`, `package`, `print`, `printf`, `q`, `qq`, `qr`, `qw`, `qx`, `redo`, `require`, `return`, `s`, `say`, `sort`, `state`, `sub`, `tr`, `unless`, `until`, `use`, `when`, `while`, `x`, `xor`, `y`

Calling with ampersand syntax and through references does **not** work for the following functions due to special syntax:

`chdir`, `chomp`, `chop`, `defined`, `delete`, `eof`, `exec`, `exists`, `lstat`, `split`, `stat`, `system`, `truncate`, `unlink`

## Overriding Core Functions

To override a built-in per package, use the `subs` pragma at compile time:

perl
use subs 'chdir';
sub chdir { ... }
chdir $somewhere;
To override globally (in all namespaces), import into `CORE::GLOBAL` at compile time:

perl
BEGIN {
    *CORE::GLOBAL::hex = sub {
        # ... your code here
    };
}
In both cases, use `CORE::` prefix to access the original built-in.

## See Also

- [perlsub](http://localhost/phpMan.php/perldoc/perlsub/markdown)
- [perlfunc](http://localhost/phpMan.php/perldoc/perlfunc/markdown)

---
type: CommandReference
command: core
mode: man
section: 5
source: man-pages
---

## Quick Reference

- `$ cat /proc/sys/kernel/core_pattern` — show core dump naming template
- `$ echo "|/path/to/handler %p %u %g %s %t %c %e" > /proc/sys/kernel/core_pattern` — pipe core dumps to a program
- `$ sysctl -w kernel.core_pattern="%e-%s.core"` — set core file name template (temporary)
- `$ echo 0x7 > /proc/self/coredump_filter` — set dump filter for current shell
- `$ coredumpctl list` — list systemd-managed core dumps
- `$ coredumpctl dump <PID> -o core` — extract a specific core dump
- `$ gdb program core` — debug a core dump
- `$ gcore <PID>` — obtain a core dump of a running process (gdb)

## Name

core - core dump file

## Description

A core dump file is an image of a process's memory at termination, produced by default on certain signals (see [signal(7)](http://localhost/phpMan.php/man/signal/7/markdown)). It can be used with a debugger like [gdb(1)](http://localhost/phpMan.php/man/gdb/1/markdown) to inspect the program's state.

### Core dump not produced when:

- Process lacks write permission for the core file (directory not writable, or file exists and is not writable/regular).
- File exists with multiple hard links.
- Filesystem full, read-only, or quota exceeded.
- Directory does not exist.
- `RLIMIT_CORE` or `RLIMIT_FSIZE` is zero.
- Binary lacks read permission.
- Process is set-user-ID/set-group-ID (unless `/proc/sys/fs/suid_dumpable` allows).
- `/proc/sys/kernel/core_pattern` is empty and `core_uses_pid` is 0.
- Kernel configured without `CONFIG_COREDUMP`.
- `madvise(MADV_DONTDUMP)` was used.

### Naming of core dump files

Default name: `core`. Controlled by `/proc/sys/kernel/core_pattern` (since Linux 2.6/2.4.21). Template may contain `%` specifiers:

| Specifier | Substitution |
|-----------|--------------|
| `%%` | literal `%` |
| `%c` | core file size soft limit |
| `%d` | dump mode (`PR_GET_DUMPABLE`) |
| `%e` | executable name (truncated to 15 chars) |
| `%E` | executable path, `/` replaced by `!` |
| `%g` | real GID |
| `%h` | hostname |
| `%i` | TID in PID namespace |
| `%I` | TID in initial PID namespace |
| `%p` | PID in PID namespace |
| `%P` | PID in initial PID namespace |
| `%s` | signal number |
| `%t` | time of dump (epoch) |
| `%u` | real UID |

Maximum filename length: 128 bytes (64 bytes before 2.6.19). Default: `core`. If `%p` not included and `/proc/sys/kernel/core_uses_pid` is nonzero, `.PID` is appended.

Paths are interpreted relative to the crashing process's mount namespace, cwd, and root.

If `/proc/sys/fs/suid_dumpable` is set to 2 (suid-safe), the pattern must be an absolute path or a pipe.

### Piping core dumps to a program

If the first character of `/proc/sys/kernel/core_pattern` is `|`, the remainder is the command line of a program (absolute path) that receives the core dump on stdin. The program runs as user/group root in the initial namespaces, with cwd set to root. The `RLIMIT_CORE` limit is not enforced.

### `/proc/sys/kernel/core_pipe_limit`

Limits concurrent piped core dumps. Default 0 (unlimited but no wait for `/proc/[pid]`). If value > 0, exceeding that count causes subsequent dumps to be skipped.

### Controlling which mappings are written to the core dump

`/proc/[pid]/coredump_filter` (bitmask, hexadecimal). Bits:

| Bit | Meaning |
|------|---------|
| 0 | Anonymous private mappings |
| 1 | Anonymous shared mappings |
| 2 | File-backed private mappings |
| 3 | File-backed shared mappings |
| 4 | ELF headers |
| 5 | Private huge pages |
| 6 | Shared huge pages |
| 7 | Private DAX pages |
| 8 | Shared DAX pages |

Default: bits 0, 1, 4 (if `CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS`), and 5. Displayed as `33`. Can be set at boot via `coredump_filter` boot option.

Memory-mapped I/O pages (e.g., frame buffer) are never dumped; vDSO pages are always dumped.

### Core dumps and systemd

On systems with systemd, `core_pattern` typically pipes to `systemd-coredump`. Core dumps are stored as compressed files in `/var/lib/systemd/coredump/`. Use `coredumpctl list` to list and `coredumpctl dump <PID> -o <file>` to extract.

To restore traditional behavior, set an override:

shell
# echo "kernel.core_pattern=core.%p" > /etc/sysctl.d/50-coredump.conf
# /lib/systemd/systemd-sysctl
To temporarily change pattern:

shell
# sysctl -w kernel.core_pattern="%e-%s.core"
## Examples

### Pipe core dump to a custom program

shell
# echo "|/path/to/core_pattern_pipe_test %p UID=%u GID=%g sig=%s" > /proc/sys/kernel/core_pattern
# sleep 100
^\   # control-backslash
Quit (core dumped)
$ cat core.info
argc=5
argc[0]=</home/mtk/core_pattern_pipe_test>
argc[1]=<20575>
argc[2]=<UID=1000>
argc[3]=<GID=100>
argc[4]=<sig=3>
Total bytes in core dump: 282624
### Program source (`core_pattern_pipe_test.c`)

c
#define _GNU_SOURCE
#include <sys/stat.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define BUF_SIZE 1024

int main(int argc, char *argv[])
{
    ssize_t nread, tot;
    char buf[BUF_SIZE];
    FILE *fp;
    char cwd[PATH_MAX];

    snprintf(cwd, PATH_MAX, "/proc/%s/cwd", argv[1]);
    chdir(cwd);

    fp = fopen("core.info", "w+");
    if (fp == NULL) exit(EXIT_FAILURE);

    fprintf(fp, "argc=%d\n", argc);
    for (int j = 0; j < argc; j++)
        fprintf(fp, "argc[%d]=<%s>\n", j, argv[j]);

    tot = 0;
    while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0)
        tot += nread;
    fprintf(fp, "Total bytes in core dump: %zd\n", tot);

    fclose(fp);
    exit(EXIT_SUCCESS);
}
### Set coredump_filter before running a program

shell
$ echo 0x7 > /proc/self/coredump_filter
$ ./some_program
## See Also

- [bash(1)](http://localhost/phpMan.php/man/bash/1/markdown)
- [coredumpctl(1)](http://localhost/phpMan.php/man/coredumpctl/1/markdown)
- [gdb(1)](http://localhost/phpMan.php/man/gdb/1/markdown)
- [getrlimit(2)](http://localhost/phpMan.php/man/getrlimit/2/markdown)
- [mmap(2)](http://localhost/phpMan.php/man/mmap/2/markdown)
- [prctl(2)](http://localhost/phpMan.php/man/prctl/2/markdown)
- [sigaction(2)](http://localhost/phpMan.php/man/sigaction/2/markdown)
- [elf(5)](http://localhost/phpMan.php/man/elf/5/markdown)
- [proc(5)](http://localhost/phpMan.php/man/proc/5/markdown)
- [signal(7)](http://localhost/phpMan.php/man/signal/7/markdown)
- [systemd-coredump(8)](http://localhost/phpMan.php/man/systemd-coredump/8/markdown)