Provided by: manpages-ja_0.5.0.0.20221215+dfsg-1_all 

名前
core - コアダンプファイル
説明
ある種のシグナルを受けた場合のデフォルトのアクションは、 プロセスを終了し (terminate)、 コアダンプファイ ル (core dump file) を生成することである。コアダンプファイルは、ディスク上に生成される 終了時のプロセスの メモリーイメージを内容とするファイルである。 このイメージをデバッガ (例えば gdb(1)) に読み込んで、 プロ グラムが終了した時点のプログラムの状態を検査することができる。 どのシグナルを受けたときにプロセスがコアダ ンプを生成するかのリストは signal(7) に書かれている。 プロセスはソフトリソース制限 RLIMIT_CORE を設定することで、「コアダンプ」シグナルを受信した際に生成される コアダンプファイルのサイズに上限を課すことができる。詳細は getrlimit(2) を参照。 コアダンプファイルが生成されない状況がいくつかある: * プロセスがコアファイルを書き込む許可を持たない場合 (デフォルトでは、コアファイルは core か core.pid (pid はコアダンプを行うプロセスの ID) という名前で、カレントワーキングディレクトリに生成される。 命名 規則の詳細は下記を参照)。 コアファイルを生成しようとしたディレクトリが書き込み可能でない場合、 もしく は同じ名前のファイルが存在し、そのファイルが書き込み可能でも 通常のファイルでもない場合 (例えば、ディ レクトリやシンボリックリンク)、 コアファイルの生成は失敗する。 * コアダンプに使おうとしたのと同じ名前の (書き込み可能な、通常の) ファイルが すでに存在し、そのファイル に対するハードリンクが 2個以上ある場合。 * コアダンプファイルを生成しようとしたファイルシステムがフルであるか、 inode が全て使用されているか、読 み込み専用でマウントされている場合。 または、そのユーザーのディスク使用量がそのファイルシステムの ク オータ (quota) に達している。 * コアダンプファイルを生成しようとしたディレクトリが存在しない場合。 * プロセス毎のリソース制限 RLIMIT_CORE (コアファイルのサイズ) か RLIMIT_FSIZE (ファイルサイズ) が 0 に設 定されている場合。 getrlimit(2) やシェルの ulimit コマンドのドキュメント (csh(1) の limit) を参照。 * The binary being executed by the process does not have read permission enabled. (This is a security measure to ensure that an executable whose contents are not readable does not produce a—possibly readable—core dump containing an image of the executable.) * The process is executing a set-user-ID (set-group-ID) program that is owned by a user (group) other than the real user (group) ID of the process, or the process is executing a program that has file capabilities (see capabilities(7)). (However, see the description of the prctl(2) PR_SET_DUMPABLE operation, and the description of the /proc/sys/fs/suid_dumpable file in proc(5).) * /proc/sys/kernel/core_pattern is empty and /proc/sys/kernel/core_uses_pid contains the value 0. (These files are described below.) Note that if /proc/sys/kernel/core_pattern is empty and /proc/sys/kernel/core_uses_pid contains the value 1, core dump files will have names of the form .pid, and such files are hidden unless one uses the ls(1) -a option. * (Linux 3.7 以降) カーネルの設定で CONFIG_COREDUMP オプションが有効になっていない。 上記に加えて、 madvise(2) の MADV_DONTDUMP フラグが使用されている場合、プロセスのアドレス空間の一部がコア ダンプから除外される場合がある。 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. コアダンプファイルの名前 デフォルトでは、コアダンプファイルの名前は core となるが、コアダンプファイルの名前を決めるのに使われるテ ンプレートを /proc/sys/kernel/core_pattern ファイルに定義することで、ファイル名を変更することができる (/proc/sys/kernel/core_pattern は Linux 2.6 および 2.4.21 以降で利用できる)。 テンプレートには % 指示子 (specifier) を入れることができる。 これはコアファイルが生成される際に、以下の値に置き換えられる。 %% 1 つの % 文字。 %c クラッシュしたプロセスのコアファイルのサイズに関するソフトリソース上限 (Linux 2.6.24 以降)。 %d ダンプモード — prctl(2) PR_GET_DUMPABLE が返す値と同じ (Linux 3.7 以降)。 %e The process or thread's comm value, which typically is the same as the executable filename (without path prefix, and truncated to a maximum of 15 characters), but may have been modified to be something different; see the discussion of /proc/[pid]/comm and /proc/[pid]/task/[tid]/comm in proc(5). %E 実行ファイルのパス名。スラッシュ ('/') は感嘆符 ('!') に置き換えられる。 (Linux 3.0 以降) %g ダンプされたプロセスの実グループ ID (real GID) の数値。 %h ホスト名 (uname(2) で返される nodename と同じ)。 %i コアダンプのきっかけとなったスレッドの TID; そのスレッドが属している PID 名前空間での TID (Linux 3.18 以降)。 %I コアダンプのきっかけとなったスレッドの TID; そのスレッドの初期 PID 名前空間での TID (Linux 3.18 以降)。 %p ダンプされるプロセスの PID; そのプロセスが属している PID 名前空間での PID。 %P ダンプされるプロセスの PID; 初期 PID 名前空間での PID (Linux 3.12 以降)。 %s ダンプを引き起こしたシグナルの番号。 %t ダンプ時刻、紀元 (Epoch; 1970-01-01 00:00:00 +0000 (UTC)) からの秒数。 %u ダンプされたプロセスの実ユーザー ID (real UID) の数値。 テンプレートの末尾に 1 個だけ % がある場合、 その % はコアファイル名には含められない。また、上で列挙され て いない % と文字の組み合わせがあった場合も同様である。 テンプレートにおける他の文字は、 コアファイル名 としてそのまま使われる。 テンプレートには '/' 文字を入れることができ、 ディレクトリ名の区切り文字と解釈さ れる。 結果として生成されるコアファイル名の最大サイズは 128 バイトである (2.6.19 より前のカーネルでは 64 バイト)。 このファイルのデフォルト値は "core" である。 以前のものとの互換性のため、 /proc/sys/kernel/core_pattern に %p が含まれず、 かつ /proc/sys/kernel/core_uses_pid (下記参照) が 0 でな い場合は、.PID がコアファイル名に追加される。 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)). バージョン 2.4 以降の Linux では コアダンプファイルの名前を制御する原始的な方法も提供されている。 /proc/sys/kernel/core_uses_pid ファイルに値 0 が書かれている場合、コアダンプファイルは単純に core という 名前になる。このファイルに 0 以外の値が書かれている場合、 コアダンプファイルは core.PID という形式の名前 になり、ファイル名にプロセス ID が含まれる。 Linux 3.6 以降では、/proc/sys/fs/suid_dumpable が 2 ("suidsafe") に設定されている場合、テンプレートは、絶 対パス名 (先頭に '/' 文字があるパス名) かパイプ (以下で説明) のどちらかでなければならない。 コアダンプのプログラムへのパイプ カーネル 2.6.19 以降では、Linux は /proc/sys/kernel/core_pattern ファイルの別の構文をサポートしている。 このファイルの最初の文字がパイプ記号 (|) であれば、 その行の残りの部分は実行されるユーザー空間プログラム のコマンドラインとして解釈される。 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. コアダンプは、ファイルに書き込まれるのではなく、 プログラムの標準入力として渡される。 以下の点に注意する こと。 * プログラムは絶対パス名 (もしくはルートディレクトリ / からの 相対パス名) で指定されなければならない。 また、'|' 文字の直後から始めなければならない。 * コマンドライン引数には、上記のリストにある % 指示子を含めることができる。 例えば、ダンプされるプロセス の PID を渡すには、 引数に %p を指定する。 * プログラムを実行するために生成されるプロセスは、 ユーザー、グループとも root として実行される。 * Running as root does not confer any exceptional security bypasses. Namely, LSMs (e.g., SELinux) are still active and may prevent the handler from accessing details about the crashed process via /proc/[pid]. * The program pathname is interpreted with respect to the initial mount namespace as it is always executed there. It is not affected by the settings (e.g., root directory, mount namespace, current working directory) of the crashing process. * The process runs in the initial namespaces (PID, mount, user, and so on) and not in the namespaces of the crashing process. One can utilize specifiers such as %P to find the right /proc/[pid] directory and probe/enter the crashing process's namespaces if needed. * The process starts with its current working directory as the root directory. If desired, it is possible change to the working directory of the dumping process by employing the value provided by the %P specifier to change to the location of the dumping process via /proc/[pid]/cwd. * コマンドライン引数をプログラムに与えることができ (Linux 2.6.24 以降)、 引数はホワイトスペースで区切る (1行の最大長は 128 バイトが上限である)。 * The RLIMIT_CORE limit is not enforced for core dumps that are piped to a program via this mechanism. /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. どのマッピングをコアダンプに書き込むかを制御する カーネル 2.6.23 以降では、Linux 固有のファイル /proc/[pid]/coredump_filter を使って、対応するプロセス ID を持つプロセスに対してコアダンプが行われる 際に、どのメモリーセグメントをコアダンプファイルに書き込むかを 制御できる。 このファイルの値はメモリーマッピング種別 (mmap(2) 参照) のビットマスクである。 マスク内のあるビットが セットされると、そのビットに対応する種別の メモリーマッピングがダンプされる。セットされていないものはダン プされない。 このファイルの各ビットは以下の意味を持つ。 bit 0 無名のプライベートマッピング (anonymous private mappings) をダンプする。 bit 1 無名の共有マッピング (anonymous shared mappings) をダンプする。 bit 2 ファイルと関連付けられたプライベートマッピング (file-backed private mappings) をダンプする。 bit 3 ファイルと関連付けられた共有マッピング (file-backed shared mappings) をダンプする。 bit 4 (Linux 2.6.24 以降) ELF ヘッダーをダンプする。 bit 5 (Linux 2.6.28 以降) プライベートなヒュージページ (private huge page) をダンプする。 bit 6 (Linux 2.6.28 以降) 共有されたヒュージページ (shared huge page) をダンプする。 bit 7 (Linux 4.4 以降) プライベートな DAX ページをダンプする。 bit 8 (Linux 4.4 以降) 共有された DAX ページをダンプする。 デフォルトでは、ビット 0, 1, 4, 5 がセットされる。 (ビット 4 がセットされるのは、カーネルが設定オプション CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS を有効にして作成された場合である)。このデフォルト値は coredump_filter ブートオプションを使うことで起動時に変更できる。 The value of this file is displayed in hexadecimal. (The default value is thus displayed as 33.) coredump_filter の値に関わらず、フレームバッファーなどの memory-mapped I/O に関する ページは決してダンプ されず、仮想 DSO ページ (vdso(7)) は常にダンプされる。 fork(2) で作成される子プロセスは親プロセスの coredump_filter の値を継承する。 execve(2) の前後で coredump_filter の値は保持される。 例のように、プログラムを実行する前に親シェルの coredump_filter を設定しておくと役立つことがある。 $ echo 0x7 > /proc/self/coredump_filter $ ./some_program このファイルが提供されるのは、カーネルが設定オプション CONFIG_ELF_CORE を有効にして作成された場合だけであ る。 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"
注意
gdb(1) の gcore コマンドを使用すると、実行中のプロセスのコアダンプを取得できる。 バージョン 2.6.27 以前の Linux では、 マルチスレッドプロセス (より正確には、 clone(2) の CLONE_VM で生成 された別プロセスとメモリーを共有しているプロセス) がコアダンプを生成する場合、 コアファイル名にプロセス ID が必ず付加される。 ただし、 /proc/sys/kernel/core_pattern の %p 指定によりコアファイル名のどこか他の場 所にプロセス ID が すでに含まれている場合は、プロセス ID が末尾に付加されない。 (この機能が主に役に立つの はすでに使われなくなった LinuxThreads 実装を利用している場合である。 LinuxThreads 実装では、プロセス内の 個々のスレッドは異なるプロセス ID を持つ。)
例
以下のプログラムは /proc/sys/kernel/core_pattern ファイルのパイプ構文の使用例を示している。 以下のシェル のセッションはこのプログラムの使用例を示すものである (コンパイルして 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 プログラムのソース /* 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); }
関連項目
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)
この文書について
この man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告 に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。