info > CORE

CORE(3perl) β€” Perl Programmers Reference Guide

πŸ“ NAME

πŸ”Ή CORE - Namespace for Perl's core routines

πŸš€ Quick Reference

Use CaseCommandDescription
Override a built-in function (local scope)use subs 'chdir'; sub chdir { ... }Override chdir in the current package
Override a built-in globallyBEGIN { *CORE::GLOBAL::hex = sub { ... }; }Replace hex in all namespaces
Call the original built-in after overrideCORE::hex("0x50")Force use of the original function
Take a reference to a core function*shove = \&CORE::push;Alias push as shove
List all built-in functionsperldoc perlfuncSee the full list of Perl built-ins

πŸ“– SYNOPSIS

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 gives access to the original built-in functions of Perl. The CORE package is built into Perl, and therefore you do not need to use or require a hypothetical CORE module prior to accessing routines in this namespace.

πŸ”Ή A list of the built-in functions in Perl can be found in perlfunc.

πŸ”Ή For all Perl keywords, a CORE:: prefix will force the built-in function to be used, even if it has been overridden or would normally require the feature pragma. Despite appearances, this has nothing to do with the CORE package, but is part of Perl's syntax.

πŸ”Ή For many Perl functions, the CORE package contains real subroutines. This feature is new in Perl 5.16. You can take references to these and make aliases. However, some can only be called as barewords; i.e., you cannot use ampersand syntax (&foo) or call them through references. See the shove example above. These subroutines exist for all keywords except the following:

πŸ”Ή Calling with ampersand syntax and through references does not work for the following functions, as they have special syntax that cannot always be translated into a simple list (e.g., eof vs eof()):

πŸ”„ OVERRIDING CORE FUNCTIONS

πŸ”Ή To override a Perl built-in routine with your own version, you need to import it at compile-time. This can be conveniently achieved with the subs pragma. This will affect only the package in which you've imported the said subroutine:

use subs 'chdir';
sub chdir { ... }
chdir $somewhere;

πŸ”Ή To override a built-in globally (that is, in all namespaces), you need to import your function into the CORE::GLOBAL pseudo-namespace at compile time:

BEGIN {
    *CORE::GLOBAL::hex = sub {
        # ... your code here
    };
}

πŸ”Ή The new routine will be called whenever a built-in function is called without a qualifying package:

print hex("0x50"),"\n";                     # prints 1

πŸ”Ή In both cases, if you want access to the original, unaltered routine, use the CORE:: prefix:

print CORE::hex("0x50"),"\n";               # prints 80

✍️ AUTHOR

πŸ”Ή This documentation provided by Tels <nospam-abuse@bloodgate.com> 2007.

πŸ”— SEE ALSO

πŸ”Ή perlsub, perlfunc.


CORE(5) β€” Linux Programmer's Manual

πŸ“ NAME

πŸ”Ή core - core dump file

πŸš€ Quick Reference

Use CaseCommandDescription
List core dumps (systemd)coredumpctl listShow all recorded core dumps
Extract a core dump by PIDcoredumpctl dump 2955 -o coreSave the core dump to a file
Disable systemd core archivingecho "kernel.core_pattern=core.%p" > /etc/sysctl.d/50-coredump.confRestore traditional core naming
Set custom core pattern temporarilysysctl -w kernel.core_pattern="%e-%s.core"Include signal and executable in name
Filter dumped memory mappingsecho 0x7 > /proc/self/coredump_filterControl which memory segments are written

πŸ“– DESCRIPTION

πŸ”Ή The default action of certain signals is to cause a process to terminate and produce a core dump file, a file containing an image of the process's memory at the time of termination. This image can be used in a debugger (e.g., gdb(1)) to inspect the state of the program at the time that it terminated. A list of the signals which cause a process to dump core can be found in signal(7).

πŸ”Ή A process can set its soft RLIMIT_CORE resource limit to place an upper limit on the size of the core dump file that will be produced if it receives a "core dump" signal; see getrlimit(2) for details.

πŸ”Ή There are various circumstances in which a core dump file is not produced:

πŸ”Ή In addition, a core dump may exclude part of the address space of the process if the madvise(2) MADV_DONTDUMP flag was employed.

πŸ”Ή On systems that employ systemd(1) as the init framework, core dumps may instead be placed in a location determined by systemd(1). See below for further details.

🏷️ Naming of core dump files

πŸ”Ή By default, a core dump file is named core, but the /proc/sys/kernel/core_pattern file (since Linux 2.6 and 2.4.21) can be set to define a template that is used to name core dump files. The template can contain % specifiers which are substituted by the following values when a core file is created:

πŸ”Ή A single % at the end of the template is dropped from the core filename, as is the combination of a % followed by any character other than those listed above. All other characters in the template become a literal part of the core filename. The template may include '/' characters, which are interpreted as delimiters for directory names. The maximum size of the resulting core filename is 128 bytes (64 bytes in kernels before 2.6.19). The default value in this file is "core". For backward compatibility, if /proc/sys/kernel/core_pattern does not include %p and /proc/sys/kernel/core_uses_pid (see below) is nonzero, then .PID will be appended to the core filename.

πŸ”Ή Paths are interpreted according to the settings that are active for the crashing process. That means the crashing process's mount namespace (see mount_namespaces(7)), its current working directory (found via getcwd(2)), and its root directory (see chroot(2)).

πŸ”Ή Since version 2.4, Linux has also provided a more primitive method of controlling the name of the core dump file. If the /proc/sys/kernel/core_uses_pid file contains the value 0, then a core dump file is simply named core. If this file contains a nonzero value, then the core dump file includes the process ID in a name of the form core.PID.

πŸ”Ή Since Linux 3.6, if /proc/sys/fs/suid_dumpable is set to 2 ("suid-safe"), the pattern must be either an absolute pathname (starting with a leading '/' character) or a pipe, as defined below.

πŸ“¦ Piping core dumps to a program

πŸ”Ή Since kernel 2.6.19, Linux supports an alternate syntax for the /proc/sys/kernel/core_pattern file. If the first character of this file is a pipe symbol (|), then the remainder of the line is interpreted as the command-line for a user-space program (or script) that is to be executed.

πŸ”Ή Since kernel 5.3.0, the pipe template is split on spaces into an argument list before the template parameters are expanded. In earlier kernels, the template parameters are expanded first and the resulting string is split on spaces into an argument list. This means that in earlier kernels executable names added by the %e and %E template parameters could get split into multiple arguments. So the core dump handler needs to put the executable names as the last argument and ensure it joins all parts of the executable name using spaces. Executable names with multiple spaces in them are not correctly represented in earlier kernels, meaning that the core dump handler needs to use mechanisms to find the executable name.

πŸ”Ή Instead of being written to a file, the core dump is given as standard input to the program. Note the following points:

βš™οΈ /proc/sys/kernel/core_pipe_limit

πŸ”Ή When collecting core dumps via a pipe to a user-space program, it can be useful for the collecting program to gather data about the crashing process from that process's /proc/[pid] directory. In order to do this safely, the kernel must wait for the program collecting the core dump to exit, so as not to remove the crashing process's /proc/[pid] files prematurely. This in turn creates the possibility that a misbehaving collecting program can block the reaping of a crashed process by simply never exiting.

πŸ”Ή Since Linux 2.6.32, the /proc/sys/kernel/core_pipe_limit can be used to defend against this possibility. The value in this file defines how many concurrent crashing processes may be piped to user-space programs in parallel. If this value is exceeded, then those crashing processes above this value are noted in the kernel log and their core dumps are skipped.

πŸ”Ή A value of 0 in this file is special. It indicates that unlimited processes may be captured in parallel, but that no waiting will take place (i.e., the collecting program is not guaranteed access to /proc/<crashing-PID>). The default value for this file is 0.

πŸ”§ Controlling which mappings are written to the core dump

πŸ”Ή Since kernel 2.6.23, the Linux-specific /proc/[pid]/coredump_filter file can be used to control which memory segments are written to the core dump file in the event that a core dump is performed for the process with the corresponding process ID.

πŸ”Ή The value in the file is a bit mask of memory mapping types (see mmap(2)). If a bit is set in the mask, then memory mappings of the corresponding type are dumped; otherwise they are not dumped. The bits in this file have the following meanings:

πŸ”Ή By default, the following bits are set: 0, 1, 4 (if the CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS kernel configuration option is enabled), and 5. This default can be modified at boot time using the coredump_filter boot option.

πŸ”Ή The value of this file is displayed in hexadecimal. (The default value is thus displayed as 33.)

πŸ”Ή Memory-mapped I/O pages such as frame buffer are never dumped, and virtual DSO (vdso(7)) pages are always dumped, regardless of the coredump_filter value.

πŸ”Ή A child process created via fork(2) inherits its parent's coredump_filter value; the coredump_filter value is preserved across an execve(2).

πŸ”Ή It can be useful to set coredump_filter in the parent shell before running a program, for example:

$ echo 0x7 > /proc/self/coredump_filter
$ ./some_program

πŸ”Ή This file is provided only if the kernel was built with the CONFIG_ELF_CORE configuration option.

🏠 Core dumps and systemd

πŸ”Ή On systems using the systemd(1) init framework, core dumps may be placed in a location determined by systemd(1). To do this, systemd(1) employs the core_pattern feature that allows piping core dumps to a program. One can verify this by checking whether core dumps are being piped to the systemd-coredump(8) program:

$ cat /proc/sys/kernel/core_pattern
|/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %e

πŸ”Ή In this case, core dumps will be placed in the location configured for systemd-coredump(8), typically as lz4(1) compressed files in the directory /var/lib/systemd/coredump/. One can list the core dumps that have been recorded by systemd-coredump(8) using coredumpctl(1):

$ coredumpctl list | tail -5
Wed 2017-10-11 22:25:30 CEST  2748 1000 1000 3 present  /usr/bin/sleep
Thu 2017-10-12 06:29:10 CEST  2716 1000 1000 3 present  /usr/bin/sleep
Thu 2017-10-12 06:30:50 CEST  2767 1000 1000 3 present  /usr/bin/sleep
Thu 2017-10-12 06:37:40 CEST  2918 1000 1000 3 present  /usr/bin/cat
Thu 2017-10-12 08:13:07 CEST  2955 1000 1000 3 present  /usr/bin/cat

πŸ”Ή The information shown for each core dump includes the date and time of the dump, the PID, UID, and GID of the dumping process, the signal number that caused the core dump, and the pathname of the executable that was being run by the dumped process. Various options to coredumpctl(1) allow a specified coredump file to be pulled from the systemd(1) location into a specified file. For example, to extract the core dump for PID 2955 shown above to a file named core in the current directory, one could use:

$ coredumpctl dump 2955 -o core

πŸ”Ή For more extensive details, see the coredumpctl(1) manual page.

πŸ”Ή To (persistently) disable the systemd(1) mechanism that archives core dumps, restoring to something more like traditional Linux behavior, one can set an override for the systemd(1) mechanism, using something like:

# echo "kernel.core_pattern=core.%p" > \
               /etc/sysctl.d/50-coredump.conf
# /lib/systemd/systemd-sysctl

πŸ”Ή It is also possible to temporarily (i.e., until the next reboot) change the core_pattern setting using a command such as the following (which causes the names of core dump files to include the executable name as well as the number of the signal which triggered the core dump):

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

πŸ“ NOTES

πŸ”Ή The gdb(1) gcore command can be used to obtain a core dump of a running process.

πŸ”Ή In Linux versions up to and including 2.6.27, if a multithreaded process (or, more precisely, a process that shares its memory with another process by being created with the CLONE_VM flag of clone(2)) dumps core, then the process ID is always appended to the core filename, unless the process ID was already included elsewhere in the filename via a %p specification in /proc/sys/kernel/core_pattern. (This is primarily useful when employing the obsolete LinuxThreads implementation, where each thread of a process has a different PID.)

πŸ“Š EXAMPLES

πŸ”Ή The program below can be used to demonstrate the use of the pipe syntax in the /proc/sys/kernel/core_pattern file. The following shell session demonstrates the use of this program (compiled to create an executable named core_pattern_pipe_test):

$ cc -o core_pattern_pipe_test core_pattern_pipe_test.c
$ su
Password:
# echo "|$PWD/core_pattern_pipe_test %p UID=%u GID=%g sig=%s" > \
    /proc/sys/kernel/core_pattern
# exit
$ sleep 100
^\                     # type 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 */

#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];

    /* Change our current working directory to that of the
       crashing process */

    snprintf(cwd, PATH_MAX, "/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(EXIT_FAILURE);

    /* Display command-line arguments given to core_pattern
       pipe program */

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

    /* Count bytes in standard input (the core dump) */

    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);
}

πŸ”— SEE ALSO

πŸ”Ή bash(1), coredumpctl(1), gdb(1), getrlimit(2), mmap(2), prctl(2), sigaction(2), elf(5), proc(5), pthreads(7), signal(7), systemd-coredump(8)

πŸ“œ COLOPHON

πŸ”Ή This page is part of release 5.10 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.

CORE
CORE(3perl) β€” Perl Programmers Reference Guide πŸ“ NAME πŸš€ Quick Reference πŸ“– SYNOPSIS πŸ“š DESCRIPTION πŸ”„ OVERRIDING CORE FUNCTIONS ✍️ AUTHOR πŸ”— SEE ALSO CORE(5) β€” Linux Programmer's Manual πŸ“ NAME πŸš€ Quick Reference πŸ“– DESCRIPTION
🏷️ Naming of core dump files πŸ“¦ Piping core dumps to a program βš™οΈ /proc/sys/kernel/core_pipe_limit πŸ”§ Controlling which mappings are written to the core dump 🏠 Core dumps and systemd
πŸ“ NOTES πŸ“Š EXAMPLES
πŸ“„ Program source
πŸ”— SEE ALSO πŸ“œ COLOPHON

Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-14 20:20 @2600:1f28:365:80b0:4d23:66fa:c2bb:7bae
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Valid XHTML 1.0 Transitional!Valid CSS!