From: Akihiro Motoki Date: Tue, 30 Mar 2021 03:35:05 +0000 (+0900) Subject: LDP: Update draft based on the previous commit (signal) X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=49189c80fd4404c33fbc45e5e10df09443a0076c;p=linuxjm%2Fjm.git LDP: Update draft based on the previous commit (signal) --- diff --git a/manual/LDP_man-pages/draft/man2/eventfd.2 b/manual/LDP_man-pages/draft/man2/eventfd.2 index bfd0f73f..ab2cbacf 100644 --- a/manual/LDP_man-pages/draft/man2/eventfd.2 +++ b/manual/LDP_man-pages/draft/man2/eventfd.2 @@ -45,8 +45,7 @@ eventfd \- イベント通知用のファイルディスクリプターを生成 イベントを通知するためにも使うことができる。 このオブジェクトには、unsigned の 64 ビット整数 (\fIuint64_t\fP) 型のカウンターが含まれており、このカウンターはカーネルにより管理される。 このカウンターは \fIinitval\fP 引き数で指定された値で初期化される。 .PP -As its return value, \fBeventfd\fP() returns a new file descriptor that can be -used to refer to the eventfd object. +\fBeventfd\fP() は eventfd オブジェクトを参照するのに使用できる新しいファイルディスクリプターを返す。 .PP 以下の値のいくつかをビット単位の論理和 (OR) で指定することで、 \fBeventfd\fP() の振舞いを変更することができる。 .TP @@ -68,9 +67,8 @@ The following operations can be performed on the file descriptor returned by \fBeventfd\fP(): .TP \fBread\fP(2) -Each successful \fBread\fP(2) returns an 8\-byte integer. A \fBread\fP(2) fails -with the error \fBEINVAL\fP if the size of the supplied buffer is less than 8 -bytes. +\fBread\fP(2) は成功すると、8 バイトの整数を返す。 渡されたバッファーの大きさが 8 バイト未満の場合、 \fBread\fP(2) はエラー +\fBEINVAL\fP で失敗する。 .IP \fBread\fP(2) が返す値は、ホストバイトオーダ、つまり、そのホストマシンにおける整数の通常のバイトオーダである。 .IP @@ -96,9 +94,8 @@ bytes. \fBwrite\fP(2) は停止 (block) する、 もしくはファイルディスクリプターが非停止 (nonblocking) に設定されている場合はエラー \fBEAGAIN\fP で失敗する。 .IP -A \fBwrite\fP(2) fails with the error \fBEINVAL\fP if the size of the supplied -buffer is less than 8 bytes, or if an attempt is made to write the value -0xffffffffffffffff. +渡されたバッファーの大きさが 8 バイト未満の場合、もしくは 値 0xffffffffffffffff を書き込もうとした場合、 \fBwrite\fP(2) +はエラー \fBEINVAL\fP で失敗する。 .TP \fBpoll\fP(2), \fBselect\fP(2) (と同様の操作) 返されたファイルディスクリプターは、 \fBpoll\fP(2) (\fBepoll\fP(7) も同じ) や \fBselect\fP(2) @@ -137,8 +134,7 @@ eventfd ファイルディスクリプターは、これ以外のファイルデ \fIflags\fP にサポートされていない値が指定された。 .TP \fBEMFILE\fP -The per\-process limit on the number of open file descriptors has been -reached. +オープン済みのファイルディスクリプターの数がプロセスあたりの上限に 達していた。 .TP \fBENFILE\fP オープン済みのファイル総数がシステム全体の上限に達していた。 @@ -192,7 +188,7 @@ eventfd ファイルディスクリプターの重要な点は、 eventfd ファ The current value of an eventfd counter can be viewed via the entry for the corresponding file descriptor in the process's \fI/proc/[pid]/fdinfo\fP directory. See \fBproc\fP(5) for further details. -.SS "C library/kernel differences" +.SS "C ライブラリとカーネルの違い" 下層にある Linux システムコールは二種類あり、 \fBeventfd\fP() と、もっと新しい \fBeventfd2\fP() である。 \fBeventfd\fP() は \fIflags\fP 引き数を実装していない。 \fBeventfd2\fP() では上記の値の \fIflags\fP が実装されている。 glibc のラッパー関数は、 \fBeventfd2\fP() が利用可能であれば、これを使用する。 @@ -211,7 +207,7 @@ int eventfd_write(int fd, eventfd_t value); .PP これらの関数は、eventfd ファイルディスクリプターに対する読み出しと 書き込みの操作を実行し、正しいバイト数が転送された場合には 0 を返し、そうでない場合は \-1 を返す。 -.SH EXAMPLES +.SH 例 以下のプログラムは eventfd ファイルディスクリプターを生成し、 その後 fork を実行して子プロセスを生成する。 親プロセスが少しの間 sleep する間に、子プロセスは プログラムのコマンドライン引き数で指定された整数(列)をそれぞれ eventfd ファイルディスクリプターに書き込む。 親プロセスは sleep を完了すると eventfd ファイルディスクリプターから 読み出しを行う。 diff --git a/manual/LDP_man-pages/draft/man2/kill.2 b/manual/LDP_man-pages/draft/man2/kill.2 new file mode 100644 index 00000000..fcfa8133 --- /dev/null +++ b/manual/LDP_man-pages/draft/man2/kill.2 @@ -0,0 +1,150 @@ +.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992 +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. The author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\" Modified by Michael Haardt +.\" Modified by Thomas Koenig +.\" Modified 1993-07-23 by Rik Faith +.\" Modified 1993-07-25 by Rik Faith +.\" Modified 1995-11-01 by Michael Haardt +.\" +.\" Modified 1996-04-14 by Andries Brouwer +.\" [added some polishing contributed by Mike Battersby ] +.\" Modified 1996-07-21 by Andries Brouwer +.\" Modified 1997-01-17 by Andries Brouwer +.\" Modified 2001-12-18 by Andries Brouwer +.\" Modified 2002-07-24 by Michael Kerrisk +.\" Added note on historical rules enforced when an unprivileged process +.\" sends a signal. +.\" Modified 2004-06-16 by Michael Kerrisk +.\" Added note on CAP_KILL +.\" Modified 2004-06-24 by aeb +.\" Modified, 2004-11-30, after idea from emmanuel.colbus@ensimag.imag.fr +.\" +.\"******************************************************************* +.\" +.\" This file was generated with po4a. Translate the source file. +.\" +.\"******************************************************************* +.\" +.\" Japanese Version Copyright (c) 1997 Kazuyuki Tanisako +.\" all rights reserved. +.\" Translated 1997-05-17, Kazuyuki Tanisako +.\" Modified 1997-05-27, Kazuyuki Tanisako +.\" Modified 1998-02-05, Kazuyuki Tanisako +.\" Updated 2001-12-27, Kentaro Shirakata +.\" Updated 2002-01-03, Kentaro Shirakata +.\" Updated 2002-09-27, Kentaro Shirakata +.\" Updated 2005-02-27, Akihiro MOTOKI +.\" Updated 2005-12-05, Akihiro MOTOKI, Catch up to LDP man-pages 2.16 +.\" Updated 2008-08-06, Akihiro MOTOKI, LDP v3.05 +.\" +.TH KILL 2 2019\-10\-10 Linux "Linux Programmer's Manual" +.SH 名前 +kill \- プロセスにシグナルを送る +.SH 書式 +.nf +\fB#include \fP +\fB#include \fP +.PP +\fBint kill(pid_t \fP\fIpid\fP\fB, int \fP\fIsig\fP\fB);\fP +.fi +.PP +.RS -4 +glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): +.RE +.PP +.ad l +\fBkill\fP(): _POSIX_C_SOURCE +.ad b +.SH 説明 +システムコールの \fBkill\fP() は、任意のプロセスグループもしくはプロセスにシグナルを 送るのに使われる。 +.PP +\fIpid\fP に正の値を指定した場合、シグナル \fIsig\fP が \fIpid\fP で指定された ID を持つプロセスに送られる。 +.PP +\fIpid\fP に 0 を指定した場合、 呼び出し元のプロセスのプロセスグループに属するすべてのプロセスに \fIsig\fP で指定したシグナルが送られる。 +.PP +\fIpid\fP に \-1 を指定した場合、 \fIsig\fP で指定したシグナルが、 呼び出し元のプロセスがシグナルを送る許可を持つ全てのプロセスに +送られる。但し、プロセス番号 1 (\fIinit\fP) へはシグナルは送られない。 以下の関連部分も参照のこと。 +.PP +\fIpid\fP に \-1 より小さな値を指定した場合、 ID が \fI\-pid\fP のプロセスグループに属するすべてのプロセスに \fIsig\fP +で指定したシグナルが送られる。 +.PP +If \fIsig\fP is 0, then no signal is sent, but existence and permission checks +are still performed; this can be used to check for the existence of a +process ID or process group ID that the caller is permitted to signal. +.PP +For a process to have permission to send a signal, it must either be +privileged (under Linux: have the \fBCAP_KILL\fP capability in the user +namespace of the target process), or the real or effective user ID of the +sending process must equal the real or saved set\-user\-ID of the target +process. In the case of \fBSIGCONT\fP, it suffices when the sending and +receiving processes belong to the same session. (Historically, the rules +were different; see NOTES.) +.SH 返り値 +成功した場合 (少なくとも一つのシグナルが送信された場合)、 0 が返される。エラーの場合 \-1 が返され、 \fIerrno\fP が適切に設定される。 +.SH エラー +.TP +\fBEINVAL\fP +無効なシグナルを指定した。 +.TP +\fBEPERM\fP +呼び出し元のプロセスが、受信するプロセスのいずれに対しても シグナルを送る許可を持っていない。 +.TP +\fBESRCH\fP +The target process or process group does not exist. Note that an existing +process might be a zombie, a process that has terminated execution, but has +not yet been \fBwait\fP(2)ed for. +.SH 準拠 +POSIX.1\-2001, POSIX.1\-2008, SVr4, 4.3BSD. +.SH 注意 +プロセス番号 1 の \fIinit\fP プロセスに送ることができるシグナルは、 \fIinit\fP が明示的にシグナルハンドラーを設定したシグナルだけである。 +こうなっているのは、誤ってシステムをダウンさせないようにするためである。 +.PP +POSIX.1 では、 \fIkill(\-1,sig)\fP が 呼び出し元のプロセスがシグナルを送ることが出来るプロセス全てに \fIsig\fP +を送ることを要求している。 但し、システム実装時に定められたシステムプロセスは シグナルの送信対象から除外される。 Linux +では、プロセスが自分自身にシグナルを送れるようになっているが、 Linux の \fIkill(\-1,sig)\fP +は呼び出し元のプロセスにはシグナルを送らない。 +.PP +POSIX.1 では以下の動作になることを要求している。 自分自身にシグナルを送ると、シグナルを送ったスレッドがそのシグナルをブロック +しておらず、他のどのスレッドもそのシグナルを受ける状態にもなく \fBsigwait\fP(3) でそのシグナルを待ってもいない場合、 \fBkill\fP() +が返る前に少なくとも一つのブロックされていない シグナルがシグナルを送ったスレッドに配送されなければならない。 +.SS "Linux での注意" +.\" In the 0.* kernels things chopped and changed quite +.\" a bit - MTK, 24 Jul 02 +Linux では、特権のないプロセスが他のプロセスにシグナルを送信するために必要な権限についてのルールが、カーネルバージョンにより違っている。 カーネル +1.0 から 1.2.2 では、送信側の実効ユーザー ID が送信対象の実効ユーザー ID と一致するか、 送信側の実ユーザー ID +が送信対象の実ユーザー ID と一致すれば、 シグナルを送信できた。 カーネル 1.2.3 から 1.3.77では、送信側の実効ユーザー ID +が送信対象の実ユーザー ID か実効ユーザー ID のいずれかと一致すればシグナルを送信できた。 現在のルールは、POSIX.1 +に準拠しており、カーネル 1.3.78 以降で 適用されている。 +.SH バグ +バージョン 2.6.7 以前の 2.6 系のカーネルには、 プロセスグループにシグナルを送ったときに、 呼び出し元のプロセスがプロセスグループの +(全メンバーではなく) 一部のメンバーに対してのみシグナルを送る許可を持っていない場合に、 \fBkill\fP() がエラー \fBEPERM\fP +で失敗するというバグがある。 このエラーが返るにもかかわらず、そのシグナルは呼び出し元が シグナルを送る許可を持つ全てのプロセスへ送られる。 +.SH 関連項目 +\fBkill\fP(1), \fB_exit\fP(2), \fBpidfd_send_signal\fP(2), \fBsignal\fP(2), \fBtkill\fP(2), +\fBexit\fP(3), \fBkillpg\fP(3), \fBsigqueue\fP(3), \fBcapabilities\fP(7), +\fBcredentials\fP(7), \fBsignal\fP(7) +.SH この文書について +この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は +\%https://www.kernel.org/doc/man\-pages/ に書かれている。 diff --git a/manual/LDP_man-pages/draft/man2/sigaction.2 b/manual/LDP_man-pages/draft/man2/sigaction.2 new file mode 100644 index 00000000..15e37ba7 --- /dev/null +++ b/manual/LDP_man-pages/draft/man2/sigaction.2 @@ -0,0 +1,653 @@ +.\" Copyright (c) 1994,1995 Mike Battersby +.\" and Copyright 2004, 2005 Michael Kerrisk +.\" based on work by faith@cs.unc.edu +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. The author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\" Modified, aeb, 960424 +.\" Modified Fri Jan 31 17:31:20 1997 by Eric S. Raymond +.\" Modified Thu Nov 26 02:12:45 1998 by aeb - add SIGCHLD stuff. +.\" Modified Sat May 8 17:40:19 1999 by Matthew Wilcox +.\" add POSIX.1b signals +.\" Modified Sat Dec 29 01:44:52 2001 by Evan Jones +.\" SA_ONSTACK +.\" Modified 2004-11-11 by Michael Kerrisk +.\" Added mention of SIGCONT under SA_NOCLDSTOP +.\" Added SA_NOCLDWAIT +.\" Modified 2004-11-17 by Michael Kerrisk +.\" Updated discussion for POSIX.1-2001 and SIGCHLD and sa_flags. +.\" Formatting fixes +.\" 2004-12-09, mtk, added SI_TKILL + other minor changes +.\" 2005-09-15, mtk, split sigpending(), sigprocmask(), sigsuspend() +.\" out of this page into separate pages. +.\" 2010-06-11 Andi Kleen, add hwpoison signal extensions +.\" 2010-06-11 mtk, improvements to discussion of various siginfo_t fields. +.\" 2015-01-17, Kees Cook +.\" Added notes on ptrace SIGTRAP and SYS_SECCOMP. +.\" +.\"******************************************************************* +.\" +.\" This file was generated with po4a. Translate the source file. +.\" +.\"******************************************************************* +.\" +.\" Japanese Version Copyright (c) 1997 HANATAKA Shinya all rights reserved. +.\" Translated 1997-03-03, HANATAKA Shinya +.\" Modified 2000-10-02, HANATAKA Shinya +.\" Modified 2001-10-18, Akihiro MOTOKI +.\" Updated 2005-03-15, Akihiro MOTOKI +.\" Updated 2005-10-05, Akihiro MOTOKI +.\" Updated 2007-09-08, Akihiro MOTOKI, LDP v2.64 +.\" Updated 2008-08-08, Akihiro MOTOKI, LDP v3.05 +.\" Updated 2010-04-18, Akihiro MOTOKI, LDP v3.24 +.\" Updated 2013-05-01, Akihiro MOTOKI +.\" Updated 2013-05-06, Akihiro MOTOKI +.\" Updated 2013-07-22, Akihiro MOTOKI +.\" +.TH SIGACTION 2 2020\-12\-21 Linux "Linux Programmer's Manual" +.SH 名前 +sigaction, rt_sigaction \- シグナルの動作の確認と変更 +.SH 書式 +.nf +\fB#include \fP +.PP +\fBint sigaction(int \fP\fIsignum\fP\fB, const struct sigaction *\fP\fIact\fP\fB,\fP +\fB struct sigaction *\fP\fIoldact\fP\fB);\fP +.fi +.PP +.RS -4 +glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): +.RE +.PP +.ad l +\fBsigaction\fP(): _POSIX_C_SOURCE +.PP +\fIsiginfo_t\fP: _POSIX_C_SOURCE >= 199309L +.ad b +.SH 説明 +\fBsigaction\fP() システムコールは、特定のシグナルを受信した際の プロセスの動作を変更するのに使用される (シグナルの概要については +\fBsignal\fP(7) を参照)。 +.PP +\fIsignum\fP には、 \fBSIGKILL\fP と \fBSIGSTOP\fP 以外の有効なシグナルをどれでも指定できる。 +.PP +\fIact\fP が NULL 以外であれば、シグナル \fIsignum\fP の新しい動作 (action) として \fIact\fP が設定される。 +\fIoldact\fP が NULL でなければ、今までの動作が \fIoldact\fP に格納される。 +.PP +\fIsigaction\fP 構造体は以下のような感じに定義される。 +.PP +.in +4n +.EX +struct sigaction { + void (*sa_handler)(int); + void (*sa_sigaction)(int, siginfo_t *, void *); + sigset_t sa_mask; + int sa_flags; + void (*sa_restorer)(void); +}; +.EE +.in +.PP +アーキテクチャーによっては共用体 (union) が用いられており、その場合には \fIsa_handler\fP と \fIsa_sigaction\fP +の両方を同時に割り当てることはできない。 +.PP +\fIsa_restorer\fP はアプリケーションが使用することを意図したフィールドではない (POSIX は \fIsa_restorer\fP +フィールドを規定していない)。 このフィールドの詳細な目的については \fBsigreturn\fP(2) に書かれている。 +.PP +\fIsa_handler\fP specifies the action to be associated with \fIsignum\fP and is be +one of the following: +.IP * 2 +\fBSIG_DFL\fP for the default action. +.IP * +\fBSIG_IGN\fP to ignore this signal. +.IP * +A pointer to a signal handling function. This function receives the signal +number as its only argument. +.PP +If \fBSA_SIGINFO\fP is specified in \fIsa_flags\fP, then \fIsa_sigaction\fP (instead +of \fIsa_handler\fP) specifies the signal\-handling function for \fIsignum\fP. +This function receives three arguments, as described below. +.PP +\fIsa_mask\fP は、シグナルハンドラー実行中に禁止 (block) すべきシグナルのマスクを指定する +(ハンドラー実行中のシグナルの禁止は、シグナルハンドラーが起動されたスレッド のシグナルのマスクに追加することで行われる)。 さらに、 +\fBSA_NODEFER\fP フラグが指定されていない場合は、ハンドラーを起動するきっかけとなる シグナルにも \fIsa_mask\fP が適用される。 +.PP +\fIsa_flags\fP はシグナルハンドラーの動作を変更するためのフラグの集合を指定する。 \fIsa_flags\fP には、以下に示すフラグの (0 +個以上の) 論理和をとったものを指定する。 +.TP +\fBSA_NOCLDSTOP\fP +\fIsignum\fP が \fBSIGCHLD\fP の場合、 子プロセスが停止したり (子プロセスが \fBSIGSTOP\fP, \fBSIGTSTP\fP, +\fBSIGTTIN\fP, \fBSIGTTOU\fP を受けたとき) 再開したり (子プロセスが \fBSIGCONT\fP を受けたとき) したときに +\fBSIGCHLD\fP の通知を受けない。 このフラグは、 \fBSIGCHLD\fP に対してハンドラーを設定する際にのみ意味を持つ。 +.TP +\fBSA_NOCLDWAIT\fP (Linux 2.6 以降) +.\" To be precise: Linux 2.5.60 -- MTK +(Linux 2.6 以降) \fIsignum\fP が \fBSIGCHLD\fP の場合、子プロセスが終了したときに +子プロセスをゾンビプロセスに変化させない (\fBwaitpid\fP(2) も参照)。 このフラグは、 \fBSIGCHLD\fP +に対してハンドラーを設定する際、もしくはそのシグナルの処理方法を \fBSIG_DFL\fP に設定する際にのみ意味を持つ。 +.IP +\fBSIGCHLD\fP に対してハンドラーを設定する際に \fBSA_NOCLDWAIT\fP フラグをセットした場合、 子プロセスが終了した際に +\fBSIGCHLD\fP シグナルが生成されるかどうかは、 POSIX.1 では規定されていない。 Linux では、この状況で \fBSIGCHLD\fP +シグナルは生成される。 いくつかの他の実装では生成されない。 +.TP +\fBSA_NODEFER\fP +Do not add the signal to the thread's signal mask while the handler is +executing, unless the signal is specified in \fIact.sa_mask\fP. Consequently, +a further instance of the signal may be delivered to the thread while it is +executing the handler. This flag is meaningful only when establishing a +signal handler. +.IP +\fBSA_NOMASK\fP is an obsolete, nonstandard synonym for this flag. +.TP +\fBSA_ONSTACK\fP +\fBsigaltstack\fP(2) で提供される別のシグナルスタックでシグナルハンドラーを呼び出す。 +別のシグナルスタックが利用可能でなければ、デフォルトのスタックが 使用される。 このフラグはシグナルハンドラーを設定する際にのみ意味を持つ。 +.TP +\fBSA_RESETHAND\fP +Restore the signal action to the default upon entry to the signal handler. +This flag is meaningful only when establishing a signal handler. +.IP +\fBSA_ONESHOT\fP is an obsolete, nonstandard synonym for this flag. +.TP +\fBSA_RESTART\fP +いくつかのシステムコールをシグナルの通知の前後で再開できるようにして、 BSD シグナル方式 (semantics) と互換性のある動作を提供する。 +このフラグはシグナルハンドラーを設定する際にのみ意味を持つ。 \fBsignal\fP(7) に書かれているシステムコールの再開に関する議論を参照のこと。 +.TP +\fBSA_RESTORER\fP +\fIアプリケーションでの使用を意図したものではない\fP。 このフラグは C ライブラリが \fIsa_restorer\fP フィールドに "signal +trampoline" のアドレスが入っていることを示すために使用される。 詳細は \fBsigreturn\fP(2) を参照。 +.TP +\fBSA_SIGINFO\fP (Linux 2.2 以降) +.\" (The +.\" .I sa_sigaction +.\" field was added in Linux 2.1.86.) +.\" +シグナルハンドラーは一つではなく、三つの引き数を持つ。この場合は \fIsa_handler\fP のかわりに \fIsa_sigaction\fP +を設定しなければならない このフラグはシグナルハンドラーを設定する際にのみ意味を持つ。 +.SS "The siginfo_t argument to a SA_SIGINFO handler" +When the \fBSA_SIGINFO\fP flag is specified in \fIact.sa_flags\fP, the signal +handler address is passed via the \fIact.sa_sigaction\fP field. This handler +takes three arguments, as follows: +.PP +.in +4n +.EX +void +handler(int sig, siginfo_t *info, void *ucontext) +{ + ... +} +.EE +.in +.PP +These three arguments are as follows +.TP +\fIsig\fP +The number of the signal that caused invocation of the handler. +.TP +\fIinfo\fP +A pointer to a \fIsiginfo_t\fP, which is a structure containing further +information about the signal, as described below. +.TP +\fIucontext\fP +This is a pointer to a \fIucontext_t\fP structure, cast to \fIvoid\ *\fP. The +structure pointed to by this field contains signal context information that +was saved on the user\-space stack by the kernel; for details, see +\fBsigreturn\fP(2). Further information about the \fIucontext_t\fP structure can +be found in \fBgetcontext\fP(3) and \fBsignal\fP(7). Commonly, the handler +function doesn't make any use of the third argument. +.PP +The \fIsiginfo_t\fP data type is a structure with the following fields: +.PP +.in +4n +.EX +.\" FIXME +.\" The siginfo_t 'si_trapno' field seems to be used +.\" only on SPARC and Alpha; this page could use +.\" a little more detail on its purpose there. +.\" In the kernel: si_tid +siginfo_t { + int si_signo; /* Signal number */ + int si_errno; /* An errno value */ + int si_code; /* Signal code */ + int si_trapno; /* Trap number that caused + hardware\-generated signal + (unused on most architectures) */ + pid_t si_pid; /* Sending process ID */ + uid_t si_uid; /* Real user ID of sending process */ + int si_status; /* Exit value or signal */ + clock_t si_utime; /* User time consumed */ + clock_t si_stime; /* System time consumed */ + union sigval si_value; /* Signal value */ + int si_int; /* POSIX.1b signal */ + void *si_ptr; /* POSIX.1b signal */ + int si_overrun; /* Timer overrun count; + POSIX.1b timers */ + int si_timerid; /* Timer ID; POSIX.1b timers */ + void *si_addr; /* Memory location which caused fault */ + long si_band; /* Band event (was \fIint\fP in + glibc 2.3.2 and earlier) */ + int si_fd; /* File descriptor */ + short si_addr_lsb; /* Least significant bit of address + (since Linux 2.6.32) */ + void *si_lower; /* Lower bound when address violation + occurred (since Linux 3.19) */ + void *si_upper; /* Upper bound when address violation + occurred (since Linux 3.19) */ + int si_pkey; /* Protection key on PTE that caused + fault (since Linux 4.6) */ + void *si_call_addr; /* Address of system call instruction + (since Linux 3.5) */ + int si_syscall; /* Number of attempted system call + (since Linux 3.5) */ + unsigned int si_arch; /* Architecture of attempted system call + (since Linux 3.5) */ +} +.EE +.in +.PP +\fIsi_signo\fP, \fIsi_errno\fP, \fIsi_code\fP は全てのシグナルに対して定義されている (\fIsi_errno\fP は +Linux では一般的には使用されない)。 構造体の残りの部分は、共用体 (union) になっているかもしれない。 +その場合は該当するシグナルにおいて意味のあるフィールドのみを読み込む ことができる。 +.IP * 2 +\fBkill\fP(2) や \fBsigqueue\fP(3) で送信されたシグナルでは \fIsi_pid\fP と \fIsi_uid\fP が設定される。 さらに、 +\fBsigqueue\fP(3) で送信されたシグナルでは \fIsi_int\fP と \fIsi_pid\fP +にシグナルの送信者により指定された値が設定される。詳細は \fBsigqueue\fP(3) を参照。 +.IP * +POSIX.1b タイマー (Linux 2.6 以降) は \fIsi_overrun\fP と \fIsi_timerid\fP を設定する。 +\fIsi_timerid\fP フィールドはカーネルがタイマーを特定するのに使用する内部 ID であり、 \fBtimer_create\fP(2) +が返すタイマー ID と同じではない。 \fIsi_overrun\fP フィールドはタイマーが回り切った回数である。 これは +\fBtimer_getoverrun\fP(2) の呼び出しで取得できる情報と同じである。 これらのフィールドは非標準で Linux による拡張である。 +.IP * +メッセージキューの通知用に送信されたシグナル (\fBmq_notify\fP(3) の \fBSIGEV_SIGNAL\fP の説明を参照) では、 +\fIsi_int\fP/\fIsi_ptr\fP に \fBmq_notify\fP(3) に渡された \fIsigev_value\fP が設定される。 \fIsi_pid\fP +にはメッセージ送信者のプロセス ID が設定され、 \fIsi_uid\fP にはメッセージ送信者の実ユーザー ID が設定される。 +.IP * +.\" FIXME . +.\" When si_utime and si_stime where originally implemented, the +.\" measurement unit was HZ, which was the same as clock ticks +.\" (sysconf(_SC_CLK_TCK)). In 2.6, HZ became configurable, and +.\" was *still* used as the unit to return the info these fields, +.\" with the result that the field values depended on the +.\" configured HZ. Of course, the should have been measured in +.\" USER_HZ instead, so that sysconf(_SC_CLK_TCK) could be used to +.\" convert to seconds. I have a queued patch to fix this: +.\" http://thread.gmane.org/gmane.linux.kernel/698061/ . +.\" This patch made it into 2.6.27. +.\" But note that these fields still don't return the times of +.\" waited-for children (as is done by getrusage() and times() +.\" and wait4()). Solaris 8 does include child times. +\fBSIGCHLD\fP は \fIsi_pid\fP, \fIsi_uid\fP, \fIsi_status\fP, \fIsi_utime\fP, \fIsi_stime\fP +を設定し、子プロセスに関する情報を提供する。 \fIsi_pid\fP フィールドは子プロセスのプロセス ID で、 \fIsi_uid\fP +フィールドは子プロセスの実ユーザー ID である。 \fIsi_stime\fP フィールドには、 (\fIsi_code\fP が \fBCLD_EXITED\fP +の場合は) 子プロセスの終了ステータスが、それ以外の場合は状態が変化する原因となったシグナル番号が格納される。 \fIsi_utime\fP と +\fIsi_stime\fP には子プロセスが使用したユーザー CPU 時間とシステム CPU 時間がそれぞれ格納される。(\fBgetrusage\fP(2) や +\fBtimes\fP(2) と異なり) これらのフィールドには wait 待ちの子プロセスにより使用された時間は含まれない。 2.6 より前と 2.6.27 +以降のカーネルでは、 これらのフィールドに格納される CPU 時間の単位は \fIsysconf(_SC_CLK_TCK)\fP である。 2.6.27 +より前の 2.6 系のカーネルでは、バグがあり、 これらのフィールドの CPU 時間の単位が (カーネルのコンフィグで指定される) システムの +jiffy であった (\fBtime\fP(7) 参照)。 +.IP * +\fBSIGILL\fP, \fBSIGFPE\fP, \fBSIGSEGV\fP, \fBSIGBUS\fP, \fBSIGTRAP\fP では、 \fIsi_addr\fP に +fault が発生したアドレスが設定される。 いくつかのアーキテクチャーでは、 これらのシグナルは \fIsi_trapno\fP フィールドにも設定される。 +.IP +\fBSIGBUS\fP が発生するエラーのいくつか、特に \fBBUS_MCEERR_AO\fP と \fBBUS_MCEERR_AR\fP では、 +\fIsi_addr_lsb\fP も設定される。 このフィールドは報告されるアドレスの最下位ビットを示し、 これによりメモリー破壊の程度を知ることができる。 +例えば、ページ全体が壊れている場合には \fIsi_addr_lsb\fP には \fIlog2(sysconf(_SC_PAGESIZE))\fP が入る。 +\fBSIGTRAP\fP が \fBptrace\fP(2) イベント (PTRACE_EVENT_foo) に対応して配送される際、 \fIsi_addr\fP +は設定されないが、 \fIsi_pid\fP と \fIsi_uid\fP にはトラップの配送に責任を負うプロセス ID とユーザー ID がそれぞれ格納される。 +\fBseccomp\fP(2) の場合、 トレース対象はイベントを配送した元として示される。 \fBBUS_MCEERR_*\fP と +\fIsi_addr_lsb\fP は Linux 固有の拡張である。 +.IP +The \fBSEGV_BNDERR\fP suberror of \fBSIGSEGV\fP populates \fIsi_lower\fP and +\fIsi_upper\fP. +.IP +The \fBSEGV_PKUERR\fP suberror of \fBSIGSEGV\fP populates \fIsi_pkey\fP. +.IP * +\fBSIGIO\fP/\fBSIGPOLL\fP (2 つの名前は Linux では同義語) では \fIsi_band\fP と \fIsi_fd\fP が設定される。 +\fIsi_band\fP イベントは、 \fBpoll\fP(2) が \fIrevents\fP フィールドに設定するのと同じ値が入ったビットマスクである。 +\fIsi_fd\fP フィールドは I/O イベントが発生したファイルディスクリプターを示す。詳細については \fBfcntl\fP(2) の +\fBF_SETSIG\fP の説明を参照のこと。 +.IP * +.\" commit a0727e8ce513fe6890416da960181ceb10fbfae6 +.\" +seccomp フィルターが \fBSECCOMP_RET_TRAP\fP を返す際に (Linux 3.5 以降で) 生成される \fBSIGSYS\fP +シグナルでは、 \fIsi_call_addr\fP, \fIsi_syscall\fP, \fIsi_arch\fP, \fIsi_arch\fP や +\fBseccomp\fP(2) で説明されている他のフィールドが設定される。 +.SS "The si_code field" +The \fIsi_code\fP field inside the \fIsiginfo_t\fP argument that is passed to a +\fBSA_SIGINFO\fP signal handler is a value (not a bit mask) indicating why +this signal was sent. For a \fBptrace\fP(2) event, \fIsi_code\fP will contain +\fBSIGTRAP\fP and have the ptrace event in the high byte: +.PP +.in +4n +.EX +(SIGTRAP | PTRACE_EVENT_foo << 8). +.EE +.in +.PP +For a non\-\fBptrace\fP(2) event, the values that can appear in \fIsi_code\fP are +described in the remainder of this section. Since glibc 2.20, the +definitions of most of these symbols are obtained from \fI\fP +by defining feature test macros (before including \fIany\fP header file) as +follows: +.IP * 3 +\fB_XOPEN_SOURCE\fP with the value 500 or greater; +.IP * +\fB_XOPEN_SOURCE\fP and \fB_XOPEN_SOURCE_EXTENDED\fP; or +.IP * +\fB_POSIX_C_SOURCE\fP with the value 200809L or greater. +.PP +For the \fBTRAP_*\fP constants, the symbol definitions are provided only in the +first two cases. Before glibc 2.20, no feature test macros were required to +obtain these symbols. +.PP +通常のシグナルの場合には、 以下のリストに示す値がどのシグナルの場合でも \fIsi_code\fP に入りうる。シグナルが生成された理由も記載している。 +.RS 4 +.TP +\fBSI_USER\fP +\fBkill\fP(2) +.TP +\fBSI_KERNEL\fP +カーネルにより送信された +.TP +\fBSI_QUEUE\fP +\fBsigqueue\fP(3) +.TP +\fBSI_TIMER\fP +POSIX タイマーが満了した +.TP +\fBSI_MESGQ\fP (Linux 2.6.6 以降) +POSIX メッセージキューの状態が変化した; \fBmq_notify\fP(3) 参照 +.TP +\fBSI_ASYNCIO\fP +非同期 IO (AIO) が完了した +.TP +\fBSI_SIGIO\fP +\fBSIGIO\fP がキューイングされた (Linux 2.2 以下のカーネルのみ; Linux 2.4 以降では以下で説明する +\fBSIGIO\fP/\fBSIGPOLL\fP の \fIsi_code\fP が入る) +.TP +\fBSI_TKILL\fP (Linux 2.4.19 以降) +.\" SI_DETHREAD is defined in 2.6.9 sources, but isn't implemented +.\" It appears to have been an idea that was tried during 2.5.6 +.\" through to 2.5.24 and then was backed out. +\fBtkill\fP(2) または \fBtgkill\fP(2) +.RE +.PP +\fBSIGILL\fP シグナルの場合、 \fIsi_code\fP には以下の値が入る可能性がある: +.RS 4 +.TP +\fBILL_ILLOPC\fP +不正な命令コード +.TP +\fBILL_ILLOPN\fP +不正なオペランド +.TP +\fBILL_ILLADR\fP +不正なアドレッシングモード +.TP +\fBILL_ILLTRP\fP +不正なトラップ +.TP +\fBILL_PRVOPC\fP +特権が必要な命令コード +.TP +\fBILL_PRVREG\fP +特権が必要なレジスター +.TP +\fBILL_COPROC\fP +コプロセッサのエラー +.TP +\fBILL_BADSTK\fP +内部スタックエラー +.RE +.PP +\fBSIGFPE\fP シグナルの場合、 \fIsi_code\fP には以下の値が入る可能性がある: +.RS 4 +.TP +\fBFPE_INTDIV\fP +整数の 0 による除算 +.TP +\fBFPE_INTOVF\fP +整数のオーバーフロー +.TP +\fBFPE_FLTDIV\fP +浮動小数点の 0 による除算 +.TP +\fBFPE_FLTOVF\fP +浮動小数点のオーバーフロー +.TP +\fBFPE_FLTUND\fP +浮動小数点のアンダーフロー +.TP +\fBFPE_FLTRES\fP +浮動小数点の不正確な演算結果 (inexact result) +.TP +\fBFPE_FLTINV\fP +浮動小数点の不正な操作 +.TP +\fBFPE_FLTSUB\fP +範囲外の添字 (subscript) +.RE +.PP +\fBSIGSEGV\fP シグナルの場合、 \fIsi_code\fP には以下の値が入る可能性がある: +.RS 4 +.TP +\fBSEGV_MAPERR\fP +オブジェクトにマッピングされていないアドレス +.TP +\fBSEGV_ACCERR\fP +マッピングされたオブジェクトに対するアクセス許可がない +.TP +\fBSEGV_BNDERR\fP (Linux 3.19 以降) +.\" commit ee1b58d36aa1b5a79eaba11f5c3633c88231da83 +Failed address bound checks. +.TP +\fBSEGV_PKUERR\fP (Linux 4.6 以降) +.\" commit cd0ea35ff5511cde299a61c21a95889b4a71464e +Access was denied by memory protection keys. See \fBpkeys\fP(7). The +protection key which applied to this access is available via \fIsi_pkey\fP. +.RE +.PP +\fBSIGBUS\fP シグナルの場合、 \fIsi_code\fP には以下の値が入る可能性がある: +.RS 4 +.TP +\fBBUS_ADRALN\fP +不正なアドレスアライメント (alignment) +.TP +\fBBUS_ADRERR\fP +存在しない物理アドレス +.TP +\fBBUS_OBJERR\fP +オブジェクト固有のハードウェアエラー +.TP +\fBBUS_MCEERR_AR\fP (Linux 2.6.32 以降) +マシンチェックで使用中のハードウェアメモリーのエラーが検出された。対応が必須。 +.TP +\fBBUS_MCEERR_AO\fP (Linux 2.6.32 以降) +実行中にハードウェアメモリーエラーが検出されたが、使用中のメモリーではない。対応は必須ではない。 +.RE +.PP +\fBSIGTRAP\fP シグナルの場合、 \fIsi_code\fP には以下の値が入る可能性がある: +.RS 4 +.TP +\fBTRAP_BRKPT\fP +プロセスのブレークポイント +.TP +\fBTRAP_TRACE\fP +プロセスのトレーストラップ +.TP +\fBTRAP_BRANCH\fP (Linux 2.4 以降, IA64 のみ) +プロセスのブランチトラップ +.TP +\fBTRAP_HWBKPT\fP (Linux 2.4 以降, IA64 のみ) +ハードウェアのブレークポイント/ウォッチポイント +.RE +.PP +\fBSIGCHLD\fP シグナルの場合、 \fIsi_code\fP には以下の値が入る可能性がある: +.RS 4 +.TP +\fBCLD_EXITED\fP +子プロセスが終了した (exited) +.TP +\fBCLD_KILLED\fP +子プロセスが kill された +.TP +\fBCLD_DUMPED\fP +子プロセスが異常終了した +.TP +\fBCLD_TRAPPED\fP +トレース対象の子プロセスがトラップを上げた +.TP +\fBCLD_STOPPED\fP +子プロセスが停止 (stop) した +.TP +\fBCLD_CONTINUED\fP (Linux 2.6.9 以降) +停止していた子プロセスが再開した +.RE +.PP +\fBSIGIO\fP/\fBSIGPOLL\fP シグナルの場合、 \fIsi_code\fP には以下の値が入る可能性がある: +.RS 4 +.TP +\fBPOLL_IN\fP +入力データが利用可能 +.TP +\fBPOLL_OUT\fP +出力バッファーが利用可能 +.TP +\fBPOLL_MSG\fP +入力メッセージが利用可能 +.TP +\fBPOLL_ERR\fP +I/O エラー +.TP +\fBPOLL_PRI\fP +高優先の入力が利用可能 +.TP +\fBPOLL_HUP\fP +デバイスが接続されていない +.RE +.PP +\fBSIGSYS\fP シグナルの場合、 \fIsi_code\fP には以下の値が入る可能性がある: +.RS 4 +.TP +\fBSYS_SECCOMP\fP (Linux 3.5 以降) +\fBseccomp\fP(2) のフィルタールールによる配送された +.RE +.SH 返り値 +\fBsigaction\fP() 関数は成功すると 0 を返す。 エラーの場合、\-1 を返し、 \fIerrno\fP にエラーを示す値をセットする。 +.SH エラー +.TP +\fBEFAULT\fP +\fIact\fP か \fIoldact\fP が指しているメモリーが正しいプロセスのアドレス空間にない。 +.TP +\fBEINVAL\fP +無効なシグナルが指定された。補足 (catch) したり無視したりできない シグナルである \fBSIGKILL\fP や \fBSIGSTOP\fP +に対する動作を変更しようとした場合にも発生する。 +.SH 準拠 +.\" SVr4 does not document the EINTR condition. +POSIX.1\-2001, POSIX.1\-2008, SVr4. +.SH 注意 +\fBfork\fP(2) 経由で作成された子プロセスは、親プロセスのシグナルの処理方法の コピーを継承する。 \fBexecve\fP(2) +の前後で、ハンドラーが設定されているシグナルの処理方法はデフォルトにリセットされ、 無視が設定されているシグナルの処理方法は変更されずそのままとなる。 +.PP +POSIX では、 \fBkill\fP(2) や \fBraise\fP(3) で生成できないシグナル \fBSIGFPE\fP, \fBSIGILL\fP, +\fBSIGSEGV\fP を無視 (ignore) した場合、その後の動作は未定義である。 ゼロによる整数割り算の結果は未定義となる。 +アーキテクチャーによっては、このとき \fBSIGFPE\fP シグナルが生成される。 (同様に負の最大整数を \-1 で割ると \fBSIGFPE\fP +が生成されるかもしれない) このシグナルを無視すると無限ループに陥るかもしれない。 +.PP +POSIX.1\-1990 では \fBSIGCHLD\fP に \fBSIG_IGN\fP を設定することを認めていない。 POSIX.1\-2001 +とそれ以降では認められており、 \fBSIGCHLD\fP を無視することでゾンビプロセスの生成を防止することができる (\fBwait\fP(2) を参照)。 +さらに、BSD と System\ V では \fBSIGCHLD\fP を無視した際の動作が異なっている。 +そのため、完全に移植性がある方法で、終了した子プロセスがゾンビにならないこと を保証するには、 \fBSIGCHLD\fP シグナルを補足し、 +\fBwait\fP(2) などを実行するしかない。 +.PP +POSIX.1\-1990 の仕様では \fBSA_NOCLDSTOP\fP のみが定義されている。 POSIX.1\-2001 では +\fBSA_NOCLDSTOP\fP, \fBSA_NOCLDWAIT\fP, \fBSA_NODEFER\fP, \fBSA_ONSTACK\fP, +\fBSA_RESETHAND\fP, \fBSA_RESTART\fP, \fBSA_SIGINFO\fP が追加された。 UNIX +の古い実装で動かすアプリケーションで、 他の \fIsa_flags\fP フラグを使用すると移植性が下がる。 +.PP +\fBSA_RESETHAND\fP フラグは SVr4 の同じ名前のフラグと互換性がある。 +.PP +\fBSA_NODEFER\fP フラグは 1.3.9 以降のカーネルでは同じ名前の SVr4 のフラグと互換性がある。 ぞれ以前の Linux +カーネルの実装では、このフラグを設定しているシグナル だけでなく、どのシグナルでも受けることを許していた (実際には \fIsa_mask\fP +の設定により無効にできる)。 +.PP +\fBsigaction\fP() の二番目の引き数に NULL を指定して呼び出すと、現在のシグナルハンドラーを確認する +ことができる。また、二番目と三番目の引き数を NULL にて呼び出すことで、 指定されたシグナルが現在のマシンで使えるかどうかチェックできる。 +.PP +\fBSIGKILL\fP や \fBSIGSTOP\fP を (\fIsa_mask\fP に指定して) 禁止することはできない。 禁止しようとしても黙って無視される。 +.PP +シグナル集合の操作に関する詳細は \fBsigsetops\fP(3) を参照のこと。 +.PP +.\" +シグナルハンドラー内から安全に呼び出すことができる、 async\-signal\-safe functions (非同期シグナルで安全な関数) の +リストについては \fBsignal\-safety\fP(7) を参照。 +.SS "C ライブラリとカーネルの違い" +The glibc wrapper function for \fBsigaction\fP() gives an error (\fBEINVAL\fP) +on attempts to change the disposition of the two real\-time signals used +internally by the NPTL threading implementation. See \fBnptl\fP(7) for +details. +.PP +On architectures where the signal trampoline resides in the C library, the +glibc wrapper function for \fBsigaction\fP() places the address of the +trampoline code in the \fIact.sa_restorer\fP field and sets the \fBSA_RESTORER\fP +flag in the \fIact.sa_flags\fP field. See \fBsigreturn\fP(2). +.PP +.\" +The original Linux system call was named \fBsigaction\fP(). However, with the +addition of real\-time signals in Linux 2.2, the fixed\-size, 32\-bit +\fIsigset_t\fP type supported by that system call was no longer fit for +purpose. Consequently, a new system call, \fBrt_sigaction\fP(), was added to +support an enlarged \fIsigset_t\fP type. The new system call takes a fourth +argument, \fIsize_t sigsetsize\fP, which specifies the size in bytes of the +signal sets in \fIact.sa_mask\fP and \fIoldact.sa_mask\fP. This argument is +currently required to have the value \fIsizeof(sigset_t)\fP (or the error +\fBEINVAL\fP results). The glibc \fBsigaction\fP() wrapper function hides these +details from us, transparently calling \fBrt_sigaction\fP() when the kernel +provides it. +.SS 非公式 +Before the introduction of \fBSA_SIGINFO\fP, it was also possible to get some +additional information about the signal. This was done by providing an +\fIsa_handler\fP signal handler with a second argument of type \fIstruct +sigcontext\fP, which is the same structure as the one that is passed in the +\fIuc_mcontext\fP field of the \fIucontext\fP structure that is passed (via a +pointer) in the third argument of the \fIsa_sigaction\fP handler. See the +relevant Linux kernel sources for details. This use is obsolete now. +.SH バグ +When delivering a signal with a \fBSA_SIGINFO\fP handler, the kernel does not +always provide meaningful values for all of the fields of the \fIsiginfo_t\fP +that are relevant for that signal. +.PP +.\" commit 69be8f189653cd81aae5a74e26615b12871bb72e +2.6.13 以前のカーネルでは、 \fIsa_flags\fP に \fBSA_NODEFER\fP を指定した場合、 +ハンドラーが実行中に配送されたシグナル自身がマスクされなくなるだけでなく、 \fIsa_mask\fP に指定されたシグナルもマスクされなくなる。 +このバグは、カーネル 2.6.14 で修正された。 +.SH 例 +\fBmprotect\fP(2) 参照。 +.SH 関連項目 +\fBkill\fP(1), \fBkill\fP(2), \fBpause\fP(2), \fBpidfd_send_signal\fP(2), +\fBrestart_syscall\fP(2), \fBseccomp\fP(2), \fBsigaltstack\fP(2), \fBsignal\fP(2), +\fBsignalfd\fP(2), \fBsigpending\fP(2), \fBsigprocmask\fP(2), \fBsigreturn\fP(2), +\fBsigsuspend\fP(2), \fBwait\fP(2), \fBkillpg\fP(3), \fBraise\fP(3), \fBsiginterrupt\fP(3), +\fBsigqueue\fP(3), \fBsigsetops\fP(3), \fBsigvec\fP(3), \fBcore\fP(5), \fBsignal\fP(7) +.SH この文書について +この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は +\%https://www.kernel.org/doc/man\-pages/ に書かれている。 diff --git a/manual/LDP_man-pages/draft/man2/signal.2 b/manual/LDP_man-pages/draft/man2/signal.2 index c88da0a7..55f9219a 100644 --- a/manual/LDP_man-pages/draft/man2/signal.2 +++ b/manual/LDP_man-pages/draft/man2/signal.2 @@ -63,15 +63,12 @@ signal \- ANSI C シグナル操作 .PP \fBsighandler_t signal(int \fP\fIsignum\fP\fB, sighandler_t \fP\fIsighandler\fP\fB);\fP .SH 説明 -\fBWARNING\fP: - the behavior of -\fBsignal\fP() -varies across UNIX versions, -and has also varied historically across different versions of Linux. -\fBAvoid its use\fP: use -\fBsigaction\fP(2) -instead. -See \fIPortability\fP below. +\fB警告\fP: + \fBsignal\fP() の動作は UNIX のバージョンにより異なる。 +また、歴史的に見て Linux のバージョンによっても異なっている。 +\fBこのシステムコールの使用は避け、\fP +代わりに \fBsigaction\fP(2) を使用すること。 +下記の「移植性」を参照。 .PP \fBsignal\fP() はシグナル \fIsignum\fP の処理方法を \fIhandler\fP に設定する。 \fIhandler\fP には、 \fBSIG_IGN\fP、 \fBSIG_DFL\fP、 プログラマが定義した関数 (「シグナルハンドラー」) のアドレスの いずれかを指定する。 @@ -110,8 +107,8 @@ POSIX では、 \fBkill\fP(2) や \fBraise\fP(3) で生成できないシグ See \fBsigaction\fP(2) for details on what happens when the disposition \fBSIGCHLD\fP is set to \fBSIG_IGN\fP. .PP -See \fBsignal\-safety\fP(7) for a list of the async\-signal\-safe functions that -can be safely called from inside a signal handler. +シグナルハンドラー内から安全に呼び出すことができる、 async\-signal\-safe functions (非同期シングルで安全な関数) の +リストについては \fBsignal\-safety\fP(7) を参照。 .PP .\" libc4 and libc5 define .\" .IR SignalHandler ; diff --git a/manual/LDP_man-pages/draft/man2/signalfd.2 b/manual/LDP_man-pages/draft/man2/signalfd.2 new file mode 100644 index 00000000..7b8e387a --- /dev/null +++ b/manual/LDP_man-pages/draft/man2/signalfd.2 @@ -0,0 +1,321 @@ +.\" Copyright (C) 2008 Michael Kerrisk +.\" starting from a version by Davide Libenzi +.\" +.\" %%%LICENSE_START(GPLv2+_SW_3_PARA) +.\" This program is free software; you can redistribute it and/or modify +.\" it under the terms of the GNU General Public License as published by +.\" the Free Software Foundation; either version 2 of the License, or +.\" (at your option) any later version. +.\" +.\" This program is distributed in the hope that it will be useful, +.\" but WITHOUT ANY WARRANTY; without even the implied warranty of +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.\" GNU General Public License for more details. +.\" +.\" You should have received a copy of the GNU General Public +.\" License along with this manual; if not, see +.\" . +.\" %%%LICENSE_END +.\" +.\"******************************************************************* +.\" +.\" This file was generated with po4a. Translate the source file. +.\" +.\"******************************************************************* +.\" +.\" Japanese Version Copyright (c) 2008 Akihiro MOTOKI +.\" all rights reserved. +.\" Translated 2008-04-06, Akihiro MOTOKI , LDP v2.79 +.\" Updated 2008-11-10, Akihiro MOTOKI , LDP v3.13 +.\" Updated 2009-02-23, Akihiro MOTOKI , LDP v3.18 +.\" +.TH SIGNALFD 2 2020\-11\-01 Linux "Linux Programmer's Manual" +.SH 名前 +signalfd \- シグナル受け付け用のファイルディスクリプターを生成する +.SH 書式 +\fB#include \fP +.PP +\fBint signalfd(int \fP\fIfd\fP\fB, const sigset_t *\fP\fImask\fP\fB, int \fP\fIflags\fP\fB);\fP +.SH 説明 +\fBsignalfd\fP() は、呼び出し元宛てのシグナルを受け付けるために使用されるファイル ディスクリプターを生成する。 +この方法はシグナルハンドラーや \fBsigwaitinfo\fP(2) を用いる方法の代わりとなるものであり、このファイルディスクリプターを +\fBselect\fP(2), \fBpoll\fP(2), \fBepoll\fP(7) で監視できるという利点がある。 +.PP +\fImask\fP 引き数には、呼び出し元がこのファイルディスクリプター経由で受け付けたい +シグナル集合を指定する。この引き数で指定するシグナル集合の内容は、 \fBsigsetops\fP(3) +で説明されているマクロを使って初期化することができる。 通常、ファイルディスクリプター経由で受信するシグナル集合は、 +そのシグナルがデフォルトの配送方法に基いて処理されるのを防ぐために、 \fBsigprocmask\fP(2) を使ってブロックしておくべきである。 +シグナル \fBSIGKILL\fP と \fBSIGSTOP\fP を signalfd ファイルディスクリプター経由で受信することはできない。 +これらのシグナルが \fImask\fP で指定された場合には黙って無視される。 +.PP +\fIfd\fP 引き数が \-1 の場合、 \fBsignalfd\fP() は新しいファイルディスクリプターを生成し、 \fImask\fP +で指定されたシグナル集合をそのファイルディスクリプターに関連付ける。 \fIfd\fP 引き数が \-1 以外の場合、 \fIfd\fP には有効な既存の +signalfd ファイルディスクリプターを指定しなければならず、 そのディスクリプターに関連付けられているシグナル集合は \fImask\fP +を使って置き換えられる。 +.PP +Linux 2.6.27 以降では、 以下の値のいくつかをビット単位の論理和 (OR) で指定することで、 \fBsignalfd\fP() +の振舞いを変更することができる。 +.TP 14 +\fBSFD_NONBLOCK\fP +Set the \fBO_NONBLOCK\fP file status flag on the open file description (see +\fBopen\fP(2)) referred to by the new file descriptor. Using this flag saves +extra calls to \fBfcntl\fP(2) to achieve the same result. +.TP +\fBSFD_CLOEXEC\fP +新しいファイルディスクリプターに対して close\-on\-exec (\fBFD_CLOEXEC\fP) フラグをセットする。 +このフラグが役に立つ理由については、 \fBopen\fP(2) の \fBO_CLOEXEC\fP フラグの説明を参照のこと。 +.PP +バージョン 2.6.26 以前の Linux では、 \fIflags\fP 引き数は未使用であり、0 を指定しなければならない。 +.PP +\fBsignalfd\fP() が返すファイルディスクリプターは以下の操作をサポートしている。 +.TP +\fBread\fP(2) +\fImask\fP に指定されているシグナルのうち一つ以上がそのプロセスに対して 処理待ち (pending) であれば、それらのシグナルの情報が +\fBread\fP(2) に渡されたバッファーを使って、 \fIsignalfd_siginfo\fP 構造体に格納されて返される。 \fBread\fP(2) +は、バッファーに格納可能な範囲でできるだけ多くの処理待ちのシグナルに ついての情報を返す。 バッファーは最低でも \fIsizeof(struct +signalfd_siginfo)\fP バイトの大きさがなければならない。 \fBread\fP(2) の返り値は読み出されたトータルのバイト数である。 +.IP +\fBread\fP(2) が行われた結果、シグナルは消費され、 これらのシグナルはそのプロセスに対しては処理待ちではなくなる +(つまり、シグナルハンドラーで捕捉されることもなく、 \fBsigwaitinfo\fP(2) を使って受け取ることもできなくなる)。 +.IP +\fImask\fP に指定されているシグナルがそのプロセスに対して一つも処理待ちでなければ、 \fBread\fP(2) は、 \fImask\fP +で指定されたシグナルのうちいずれか一つがそのプロセスに対して発生するまで 停止 (block) する、もしくはファイルディスクリプターが非停止 +(nonblocking) に設定されている場合はエラー \fBEAGAIN\fP で失敗する。 +.TP +\fBpoll\fP(2), \fBselect\fP(2) (と同様の操作) +\fImask\fP に指定されたシグナルのうち一つ以上がそのプロセスに対して処理待ちであれば、 ファイルディスクリプターは読み出し可能となる +(\fBselect\fP(2) の \fIreadfds\fP 引き数や \fBpoll\fP(2) の \fBPOLLIN\fP フラグ)。 +.IP +signalfd ファイルディスクリプターは、これ以外のファイルディスクリプター 多重 API である \fBpselect\fP(2), +\fBppoll\fP(2), \fBepoll\fP(7) もサポートしている。 +.TP +\fBclose\fP(2) +ファイルディスクリプターがそれ以降は必要なくなった際には、クローズすべきである。 同じ signalfd +オブジェクトに関連付けられたファイルディスクリプターが全て クローズされると、そのオブジェクト用の資源がカーネルにより解放される。 +.SS "signalfd_siginfo 構造体" +signalfd ファイルディスクリプターからの \fBread\fP(2) で返される \fIsignalfd_siginfo\fP +構造体のフォーマットは以下の通りである。 +.PP +.in +4n +.EX +.\" ssi_trapno is unused on most arches +.\" ssi_addr_lsb: commit b8aeec34175fc8fe8b0d40efea4846dfc1ba663e +struct signalfd_siginfo { + uint32_t ssi_signo; /* シグナル番号 */ + int32_t ssi_errno; /* エラー番号 (未使用) */ + int32_t ssi_code; /* シグナルコード */ + uint32_t ssi_pid; /* 送信元の PID */ + uint32_t ssi_uid; /* 送信元の実 UID */ + int32_t ssi_fd; /* ファイルディスクリプター (SIGIO) */ + uint32_t ssi_tid; /* カーネルタイマー ID (POSIX タイマー) + uint32_t ssi_band; /* Band イベント (SIGIO) */ + uint32_t ssi_overrun; /* POSIX タイマーのオーバーラン回数 */ + uint32_t ssi_trapno; /* シグナルの原因となったトラップ番号 */ + int32_t ssi_status; /* 終了ステータスかシグナル (SIGCHLD) */ + int32_t ssi_int; /* sigqueue(3) から送られた整数 */ + uint64_t ssi_ptr; /* sigqueue(3) から送られたポインター */ + uint64_t ssi_utime; /* 消費したユーザー CPU 時間 (SIGCHLD) */ + uint64_t ssi_stime; /* 消費したシステム CPU 時間 (SIGCHLD) */ + uint64_t ssi_addr; /* シグナルを生成したアドレス + (ハードウェアが生成したシグナルの場合) */ + uint16_t ssi_addr_lsb; /* アドレスの最下位ビット (LSB) + (SIGBUS; Linux 2.6.37 以降) */ + uint8_t pad[\fIX\fP]; /* pad の大きさは 128 バイト + (将来のフィールド追加用の場所の確保) */ +}; +.EE +.in +.PP +\fIsignalfd_siginfo\fP 構造体の各フィールドは、 \fIsiginfo_t\fP 構造体の同じような名前のフィールドと同様である。 +\fIsiginfo_t\fP 構造体については \fBsigaction\fP(2) に説明がある。 返された \fIsignalfd_siginfo\fP +構造体の全てのフィールドがあるシグナルに対して有効なわけではない。 どのフィールドが有効かは、 \fIssi_code\fP +フィールドで返される値から判定することができる。 このフィールドは \fIsiginfo_t\fP の \fIsi_code\fP フィールドと同様である。詳細は +\fBsigaction\fP(2) を参照。 +.SS "fork(2) での扱い" +\fBfork\fP(2) が行われると、子プロセスは signalfd ファイルディスクリプターのコピーを 継承する。 +子プロセスでこのファイルディスクリプターから \fBread\fP(2) を行うと、子プロセスに対するキューに入っているシグナルに関する 情報が返される。 +.SS "Semantics of file descriptor passing" +As with other file descriptors, signalfd file descriptors can be passed to +another process via a UNIX domain socket (see \fBunix\fP(7)). In the receiving +process, a \fBread\fP(2) from the received file descriptor will return +information about signals queued to that process. +.SS "execve(2) での扱い" +他のファイルディスクリプターと全く同様に、 signalfd ファイルディスクリプターも \fBexecve\fP(2) +の前後でオープンされたままとなる。但し、そのファイルディスクリプターに close\-on\-exec のマーク (\fBfcntl\fP(2) 参照) +が付いている場合はクローズされる。 \fBexecve\fP(2) の前に読み出し可能となっていた全てのシグナルは新しく起動されたプログラム +でも引き続き読み出し可能である (これは伝統的なシグナルの扱いと同じであり、 処理待ちのブロックされたシグナルは \fBexecve\fP(2) +の前後で処理待ちのままとなる)。 +.SS スレッドでの扱い +.\" +マルチスレッドプログラムにおける signalfd ファイルディスクリプターの扱いは シグナルの標準的な扱いと全く同じである。 +言い換えると、あるスレッドが signalfd ファイルディスクリプターから 読み出しを行うと、そのスレッド自身宛てのシグナルとプロセス (すなわち +スレッドグループ全体) 宛てのシグナルが読み出される。 (スレッドは同じプロセスの他のスレッド宛てのシグナルを読み出すことはできない。) +.SS "epoll(7) semantics" +If a process adds (via \fBepoll_ctl\fP(2)) a signalfd file descriptor to an +\fBepoll\fP(7) instance, then \fBepoll_wait\fP(2) returns events only for +signals sent to that process. In particular, if the process then uses +\fBfork\fP(2) to create a child process, then the child will be able to +\fBread\fP(2) signals that are sent to it using the signalfd file descriptor, +but \fBepoll_wait\fP(2) will \fBnot\fP indicate that the signalfd file descriptor +is ready. In this scenario, a possible workaround is that after the +\fBfork\fP(2), the child process can close the signalfd file descriptor that it +inherited from the parent process and then create another signalfd file +descriptor and add it to the epoll instance. Alternatively, the parent and +the child could delay creating their (separate) signalfd file descriptors +and adding them to the epoll instance until after the call to \fBfork\fP(2). +.SH 返り値 +成功すると、 \fBsignalfd\fP() は signalfd ファイルディスクリプターを返す。 返されるファイルディスクリプターは、 \fIfd\fP が +\-1 の場合は新規のファイルディスクリプターであり、 \fIfd\fP が有効な signalfd ファイルディスクリプターだった場合は \fIfd\fP +自身である。 エラーの場合、\-1 を返し、 \fIerrno\fP にエラーを示す値を設定する。 +.SH エラー +.TP +\fBEBADF\fP +ファイルディスクリプター \fIfd\fP が有効なファイルディスクリプターでない。 +.TP +\fBEINVAL\fP +.\" or, the +.\" .I sizemask +.\" argument is not equal to +.\" .IR sizeof(sigset_t) ; +\fIfd\fP が有効な signalfd ファイルディスクリプターではない。 +.TP +\fBEINVAL\fP +\fIflags\fP が無効である。もしくは、Linux 2.6.26 以前の場合には \fIflags\fP が 0 以外である。 +.TP +\fBEMFILE\fP +オープン済みのファイルディスクリプターの数がプロセスあたりの上限に 達していた。 +.TP +\fBENFILE\fP +オープン済みのファイル総数がシステム全体の上限に達していた。 +.TP +\fBENODEV\fP +(カーネル内の) 無名 inode デバイスをマウントできなかった。 +.TP +\fBENOMEM\fP +新しい signalfd ファイルディスクリプターを生成するのに十分なメモリーがなかった。 +.SH バージョン +.\" signalfd() is in glibc 2.7, but reportedly does not build +\fBsignalfd\fP() はカーネル 2.6.22 以降の Linux で利用可能である。 正しく動作する glibc 側のサポートはバージョン +2.8 以降で提供されている。 \fBsignalfd4\fP() システムコール (「注意」参照) は カーネル 2.6.27 以降の Linux +で利用可能である。 +.SH 準拠 +\fBsignalfd\fP() と \fBsignalfd4\fP() は Linux 固有である。 +.SH 注意 +一つのプロセスは複数の signalfd ファイルディスクリプターを生成することができる。 +これにより、異なるファイルディスクリプターで異なるシグナルを受け取ることが できる (この機能は \fBselect\fP(2), \fBpoll\fP(2), +\fBepoll\fP(7) を使ってファイルディスクリプターを監視する場合に有用かもしれない。 +異なるシグナルが到着すると、異なるファイルディスクリプターが利用可能に なるからだ)。 一つのシグナルが二つ以上のファイルディスクリプターの +\fImask\fP に含まれている場合、そのシグナルの発生はそのシグナルを \fImask\fP +に含むファイルディスクリプターのうちいずれか一つから読み出すことができる。 +.PP +Attempts to include \fBSIGKILL\fP and \fBSIGSTOP\fP in \fImask\fP are silently +ignored. +.PP +.\" +The signal mask employed by a signalfd file descriptor can be viewed via the +entry for the corresponding file descriptor in the process's +\fI/proc/[pid]/fdinfo\fP directory. See \fBproc\fP(5) for further details. +.SS Limitations +The signalfd mechanism can't be used to receive signals that are +synchronously generated, such as the \fBSIGSEGV\fP signal that results from +accessing an invalid memory address or the \fBSIGFPE\fP signal that results +from an arithmetic error. Such signals can be caught only via signal +handler. +.PP +.\" +As described above, in normal usage one blocks the signals that will be +accepted via \fBsignalfd\fP(). If spawning a child process to execute a helper +program (that does not need the signalfd file descriptor), then, after the +call to \fBfork\fP(2), you will normally want to unblock those signals before +calling \fBexecve\fP(2), so that the helper program can see any signals that it +expects to see. Be aware, however, that this won't be possible in the case +of a helper program spawned behind the scenes by any library function that +the program may call. In such cases, one must fall back to using a +traditional signal handler that writes to a file descriptor monitored by +\fBselect\fP(2), \fBpoll\fP(2), or \fBepoll\fP(7). +.SS "C ライブラリとカーネルの違い" +実際の Linux のシステムコールでは \fIsize_t sizemask\fP という引き数が追加で必要である。この引き数で \fImask\fP +のサイズを指定する。 glibc の \fBsignalfd\fP() ラッパー関数にはこの引き数は含まれず、 +ラッパー関数が必要な値を計算して内部で呼び出すシステムコールに提供する。 +.PP +下層にある Linux システムコールは二種類あり、 \fBsignalfd\fP() と、もっと新しい \fBsignalfd4\fP() である。 +\fBsignalfd\fP() は \fIflags\fP 引き数を実装していない。 \fBsignalfd4\fP() では上記の値の \fIflags\fP +が実装されている。 glibc 2.9 以降では、 \fBsignalfd\fP() のラッパー関数は、 \fBsignalfd4\fP() +が利用可能であれば、これを使用する。 +.SH バグ +.\" The fix also was put into 2.6.24.5 +カーネル 2.6.25 より前では、 \fBsigqueue\fP(3) により送信されたシグナルと一緒に渡されるデータでは、フィールド +\fIssi_ptr\fP と \fIssi_int\fP は設定されない。 +.SH 例 +下記のプログラムは、シグナル \fBSIGINT\fP と \fBSIGQUIT\fP を signalfd ファイルディスクリプター経由で受信する。 シグナル +\fBSIGQUIT\fP 受信後にプログラムは終了する。 以下に示すシェルセッションにこのプログラムの使い方を示す。 +.PP +.in +4n +.EX +$\fB ./signalfd_demo\fP +\fB\(haC\fP # Control\-C generates SIGINT +Got SIGINT +\fB\(haC\fP +Got SIGINT +\fB\(ha\e\fP # Control\-\e generates SIGQUIT +Got SIGQUIT +$ +.EE +.in +.SS プログラムのソース +\& +.EX +#include +#include +#include +#include +#include + +#define handle_error(msg) \e + do { perror(msg); exit(EXIT_FAILURE); } while (0) + +int +main(int argc, char *argv[]) +{ + sigset_t mask; + int sfd; + struct signalfd_siginfo fdsi; + ssize_t s; + + sigemptyset(&mask); + sigaddset(&mask, SIGINT); + sigaddset(&mask, SIGQUIT); + + /* Block signals so that they aren\(aqt handled + according to their default dispositions */ + + if (sigprocmask(SIG_BLOCK, &mask, NULL) == \-1) + handle_error("sigprocmask"); + + sfd = signalfd(\-1, &mask, 0); + if (sfd == \-1) + handle_error("signalfd"); + + for (;;) { + s = read(sfd, &fdsi, sizeof(fdsi)); + if (s != sizeof(fdsi)) + handle_error("read"); + + if (fdsi.ssi_signo == SIGINT) { + printf("Got SIGINT\en"); + } else if (fdsi.ssi_signo == SIGQUIT) { + printf("Got SIGQUIT\en"); + exit(EXIT_SUCCESS); + } else { + printf("Read unexpected signal\en"); + } + } +} +.EE +.SH 関連項目 +\fBeventfd\fP(2), \fBpoll\fP(2), \fBread\fP(2), \fBselect\fP(2), \fBsigaction\fP(2), +\fBsigprocmask\fP(2), \fBsigwaitinfo\fP(2), \fBtimerfd_create\fP(2), \fBsigsetops\fP(3), +\fBsigwait\fP(3), \fBepoll\fP(7), \fBsignal\fP(7) +.SH この文書について +この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は +\%https://www.kernel.org/doc/man\-pages/ に書かれている。 diff --git a/manual/LDP_man-pages/draft/man2/sigpending.2 b/manual/LDP_man-pages/draft/man2/sigpending.2 index 8d31e4cc..cf4f4ce7 100644 --- a/manual/LDP_man-pages/draft/man2/sigpending.2 +++ b/manual/LDP_man-pages/draft/man2/sigpending.2 @@ -38,7 +38,7 @@ .\" .TH SIGPENDING 2 2017\-09\-15 Linux "Linux Programmer's Manual" .SH 名前 -sigpending, rt_sigpending \- examine pending signals +sigpending, rt_sigpending \- 処理待ちのシグナルの検査 .SH 書式 \fB#include \fP .PP @@ -74,7 +74,7 @@ POSIX.1\-2001, POSIX.1\-2008. .\" \fBfork\fP(2) 経由で作成された子プロセスでは、処理待ちのシグナル集合は空の集合で初期化される。 \fBexecve\fP(2) の前後で、処理待ちのシグナル集合は保持される。 -.SS "C library/kernel differences" +.SS "C ライブラリとカーネルの違い" .\" This argument is currently required to be less than or equal to .\" .IR sizeof(sigset_t) .\" (or the error diff --git a/manual/LDP_man-pages/draft/man2/sigprocmask.2 b/manual/LDP_man-pages/draft/man2/sigprocmask.2 new file mode 100644 index 00000000..8c347a37 --- /dev/null +++ b/manual/LDP_man-pages/draft/man2/sigprocmask.2 @@ -0,0 +1,151 @@ +.\" Copyright (c) 2005 Michael Kerrisk +.\" based on earlier work by faith@cs.unc.edu and +.\" Mike Battersby +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. The author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\" 2005-09-15, mtk, Created new page by splitting off from sigaction.2 +.\" +.\"******************************************************************* +.\" +.\" This file was generated with po4a. Translate the source file. +.\" +.\"******************************************************************* +.\" +.\" Japanese Version Copyright (c) 2005 Akihiro MOTOKI all rights reserved. +.\" Translated 2005-10-03, Akihiro MOTOKI +.\" Updated 2012-05-04, Akihiro MOTOKI +.\" Updated 2013-07-22, Akihiro MOTOKI +.\" +.TH SIGPROCMASK 2 2017\-09\-15 Linux "Linux Programmer's Manual" +.SH 名前 +sigprocmask, rt_sigprocmask \- 禁止するシグナルの確認と変更 +.SH 書式 +\fB#include \fP +.PP +.nf +/* Prototype for the glibc wrapper function */ +\fBint sigprocmask(int \fP\fIhow\fP\fB, const sigset_t *\fP\fIset\fP\fB, sigset_t *\fP\fIoldset\fP\fB);\fP +.PP +/* Prototype for the underlying system call */ +\fBint rt_sigprocmask(int \fP\fIhow\fP\fB, const kernel_sigset_t *\fP\fIset\fP\fB,\fP +\fB kernel_sigset_t *\fP\fIoldset\fP\fB, size_t \fP\fIsigsetsize\fP\fB);\fP +.PP +/* Prototype for the legacy system call (deprecated) */ +\fBint sigprocmask(int \fP\fIhow\fP\fB, const old_kernel_sigset_t *\fP\fIset\fP\fB,\fP +\fB old_kernel_sigset_t *\fP\fIoldset\fP\fB);\fP +.fi +.PP +.RS -4 +glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): +.RE +.PP +.ad l +\fBsigprocmask\fP(): _POSIX_C_SOURCE +.ad b +.SH 説明 +\fBsigprocmask\fP() を使うと、呼び出したスレッドのシグナルマスクの取得/変更ができる。 +シグナルマスクは、呼び出し元に対して現在配送が禁止されているシグナルの 集合のことである (詳細については \fBsignal\fP(7) も参照のこと)。 +.PP +このコールの動作は \fIhow\fP の値によって決まる: +.TP +\fBSIG_BLOCK\fP +禁止されたシグナルの集合は現在の値と \fIset\fP 引き数を結合したものとなる。 +.TP +\fBSIG_UNBLOCK\fP +現在禁止されているシグナルの集合から \fIset\fP にあるシグナルを取り除く。禁止されていないシグナルを取り除こうと することも認められている。 +.TP +\fBSIG_SETMASK\fP +禁止されているシグナルの集合に \fIset\fP 引き数を設定する。 +.PP +\fIoldset\fP が NULL でなければ、シグナルマスクの今までの値を \fIoldset\fP に格納する。 +.PP +\fIset\fP が NULL であれば、シグナルマスクは変更されない (すなわち、 \fIhow\fP は無視される)。 \fIset\fP +の値にかかわらず、現在のシグナルマスクの値は \fIoldset\fP に入れて返される (但し、 \fIoldset\fP が NULL でない場合)。 +.PP +A set of functions for modifying and inspecting variables of type +\fIsigset_t\fP ("signal sets") is described in \fBsigsetops\fP(3). +.PP +マルチスレッドのプロセスで \fBsigprocmask\fP() を使用した場合の動作は規定されていない。 \fBpthread_sigmask\fP(3) +を参照のこと。 +.SH 返り値 +\fBsigprocmask\fP() は成功した場合 0 を返す。 エラーの場合、 \-1 を返し、 \fIerrno\fP にエラーの原因を示す値を設定する。 +.SH エラー +.TP +\fBEFAULT\fP +引き数 \fIset\fP か \fIoldset\fP がプロセスに割り当てられたアドレス空間の外を指している。 +.TP +\fBEINVAL\fP +Either the value specified in \fIhow\fP was invalid or the kernel does not +support the size passed in \fIsigsetsize.\fP +.SH 準拠 +POSIX.1\-2001, POSIX.1\-2008. +.SH 注意 +\fBSIGKILL\fP や \fBSIGSTOP\fP を禁止することはできない。 禁止しようとしても黙って無視される。 +.PP +プロセス内の各スレッドはそれぞれ専用のシグナルマスクを持つ。 +.PP +\fBfork\fP(2) 経由で作成された子プロセスは親プロセスのシグナルマスクのコピーを継承する。 \fBexecve\fP(2) +の前後でシグナルマスクは保持される。 +.PP +シグナル \fBSIGBUS\fP, \fBSIGFPE\fP, \fBSIGILL\fP, \fBSIGSEGV\fP が禁止されている間に生成された場合で、 そのシグナルが +\fBkill\fP(2), \fBsigqueue\fP(3), \fBraise\fP(3) によって生成されたものでないときには、 その後の動作は未定義である。 +.PP +シグナル集合の操作に関する詳細は \fBsigsetops\fP(3) を参照のこと。 +.PP +.\" +Note that it is permissible (although not very useful) to specify both +\fIset\fP and \fIoldset\fP as NULL. +.SS "C ライブラリとカーネルの違い" +The kernel's definition of \fIsigset_t\fP differs in size from that used by the +C library. In this manual page, the former is referred to as +\fIkernel_sigset_t\fP (it is nevertheless named \fIsigset_t\fP in the kernel +sources). +.PP +The glibc wrapper function for \fBsigprocmask\fP() silently ignores attempts +to block the two real\-time signals that are used internally by the NPTL +threading implementation. See \fBnptl\fP(7) for details. +.PP +.\" sizeof(kernel_sigset_t) == _NSIG / 8, +.\" which equals to 8 on most architectures, but e.g. on MIPS it's 16. +The original Linux system call was named \fBsigprocmask\fP(). However, with +the addition of real\-time signals in Linux 2.2, the fixed\-size, 32\-bit +\fIsigset_t\fP (referred to as \fIold_kernel_sigset_t\fP in this manual page) +type supported by that system call was no longer fit for purpose. +Consequently, a new system call, \fBrt_sigprocmask\fP(), was added to support +an enlarged \fIsigset_t\fP type (referred to as \fIkernel_sigset_t\fP in this +manual page). The new system call takes a fourth argument, \fIsize_t +sigsetsize\fP, which specifies the size in bytes of the signal sets in \fIset\fP +and \fIoldset\fP. This argument is currently required to have a fixed +architecture specific value (equal to \fIsizeof(kernel_sigset_t)\fP). +.PP +.\" +The glibc \fBsigprocmask\fP() wrapper function hides these details from us, +transparently calling \fBrt_sigprocmask\fP() when the kernel provides it. +.SH 関連項目 +\fBkill\fP(2), \fBpause\fP(2), \fBsigaction\fP(2), \fBsignal\fP(2), \fBsigpending\fP(2), +\fBsigsuspend\fP(2), \fBpthread_sigmask\fP(3), \fBsigqueue\fP(3), \fBsigsetops\fP(3), +\fBsignal\fP(7) +.SH この文書について +この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は +\%https://www.kernel.org/doc/man\-pages/ に書かれている。 diff --git a/manual/LDP_man-pages/draft/man2/sigreturn.2 b/manual/LDP_man-pages/draft/man2/sigreturn.2 new file mode 100644 index 00000000..aabe0cc7 --- /dev/null +++ b/manual/LDP_man-pages/draft/man2/sigreturn.2 @@ -0,0 +1,109 @@ +.\" Copyright (C) 2008, 2014, Michael Kerrisk +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. The author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\" Created Sat Aug 21 1995 Thomas K. Dyas +.\" Modified Tue Oct 22 22:09:03 1996 by Eric S. Raymond +.\" 2008-06-26, mtk, added some more detail on the work done by sigreturn() +.\" 2014-12-05, mtk, rewrote all of the rest of the original page +.\" +.\"******************************************************************* +.\" +.\" This file was generated with po4a. Translate the source file. +.\" +.\"******************************************************************* +.\" +.\" Japanese Version Copyright (c) 1997 HANATAKA Shinya +.\" all rights reserved. +.\" Translated 1997-03-03, HANATAKA Shinya +.\" Updated 2005-09-04, Akihiro MOTOKI +.\" Updated 2008-08-07, Akihiro MOTOKI, LDP v3.05 +.\" +.TH SIGRETURN 2 2017\-09\-15 Linux "Linux Programmer's Manual" +.SH 名前 +sigreturn, rt_sigreturn \- シグナルハンドラーから返り、スタックを掃除する +.SH 書式 +\fBint sigreturn(...);\fP +.SH 説明 +.\" See arch/x86/kernel/signal.c::__setup_frame() [in 3.17 source code] +Linux カーネルがプロセスに対してブロックされていないシグナルが処理待ちと判定した場合、 そのプロセスの次回のユーザーモードへの遷移 +(すなわち、システムコールからのリターン時やそのプロセスが CPU +に再スケジュールされる際)、カーネルはユーザー空間スタックの新しいフレームを作成し、そこにプロセスコンテキストの種々の値 +(プロセッサーのステータスワード、レジスター、シグナルマスク、シグナルスタック設定) を保存する。 +.PP +また、 カーネルは、 ユーザーモードへの遷移時にシグナルハンドラーが呼び出され、 ハンドラーからのリターン時に、 制御が "signal +trampoline" と呼ばれるユーザー空間コードブロックに渡されるように、準備を行う。 signal trampoline のコードが +\fBsigreturn\fP() を呼び出す。 +.PP +\fBsigreturn\fP() は、シグナルハンドラーを起動するために行ったことの全て \(em プロセスのシグナルマスクの変更、 +シグナルスタックの切り替え (\fBsigaltstack\fP(2) 参照) \(em +の取り消しを行う。以前にユーザー空間スタックに保存された情報を使って、 \fBsigreturn\fP() +はプロセスのシグナルマスクの復元、スタックの切り替え、プロセスのコンテキスト (プロセッサフラグ、レジスター +(スタックポインター、命令ポインターを含む)) の復元を行い、 プロセスがシグナルにより割り込まれた場所から実行を再開できるようにする。 +.SH 返り値 +\fBsigreturn\fP() が返ることはない。 +.SH 準拠 +多くの UNIX 系のシステムには \fBsigreturn\fP() システムコールか似たようなシステムコールがある。 しかしながら、 このシステムコールは +POSIX には規定されておらず、 その動作の詳細はシステムにより異なる。 +.SH 注意 +.\" See sysdeps/unix/sysv/linux/sigreturn.c and +.\" signal/sigreturn.c in the glibc source +\fBsigreturn\fP() exists only to allow the implementation of signal handlers. +It should \fBnever\fP be called directly. (Indeed, a simple \fBsigreturn\fP() +wrapper in the GNU C library simply returns \-1, with \fIerrno\fP set to +\fBENOSYS\fP.) Details of the arguments (if any) passed to \fBsigreturn\fP() +vary depending on the architecture. (On some architectures, such as x86\-64, +\fBsigreturn\fP() takes no arguments, since all of the information that it +requires is available in the stack frame that was previously created by the +kernel on the user\-space stack.) +.PP +.\" See, for example, sysdeps/unix/sysv/linux/i386/sigaction.c and +.\" sysdeps/unix/sysv/linux/x86_64/sigaction.c in the glibc (2.20) source. +かつて、 UNIX システムでは signal trampoline コードがユーザースタックに置かれていた。 今日では、 +ユーザースタックのページは保護され、 コードの実行は禁止されている。 したがって、 現代の Linux システムでは、 アーキテクチャー依存ではあるが、 +signal trampoline コードは \fBvdso\fP(7) 内もしくは C ライブラリ内に置かれる。後者の場合、 C ライブラリの +\fBsigaction\fP(2) のラッパー関数は、 trampoline code の場所をそのアドレスを \fBsigaction\fP(2) 構造体の +\fIsa_restorer\fP フィールドに設定してカーネルに伝え、 \fIsa_flags\fP フィールドの \fBSA_RESTORER\fP +フラグをセットする。 +.PP +保存されたプロセスコンテキスト情報は \fIucontext_t\fP構造体に置かれる (\fI\fP 参照)。 +この構造体は、 \fBsigaction\fP(2) の \fBSA_SIGINFO\fP フラグで設定されたシグナルハンドラーの第 3 +引き数としてシングルハンドラー内で参照できる。 +.PP +.\" +他のいくつかの UNIX システムでは、 signal trampoline の扱いは少し異なる。 特に、 いくつかのシステムでは、 +ユーザーモードに戻る際に、 カーネルは制御を (シグナルハンドラーではなく) trampoline に渡し、 trampoline +コードがシグナルハンドラーを呼び出す (その後ハンドラーが返ると \fBsigreturn\fP() を呼び出す)。 +.SS "C ライブラリとカーネルの違い" +.\" +The original Linux system call was named \fBsigreturn\fP(). However, with the +addition of real\-time signals in Linux 2.2, a new system call, +\fBrt_sigreturn\fP() was added to support an enlarged \fIsigset_t\fP type. The +GNU C library hides these details from us, transparently employing +\fBrt_sigreturn\fP() when the kernel provides it. +.SH 関連項目 +\fBkill\fP(2), \fBrestart_syscall\fP(2), \fBsigaltstack\fP(2), \fBsignal\fP(2), +\fBgetcontext\fP(3), \fBsignal\fP(7), \fBvdso\fP(7) +.SH この文書について +この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は +\%https://www.kernel.org/doc/man\-pages/ に書かれている。 diff --git a/manual/LDP_man-pages/draft/man2/sigsuspend.2 b/manual/LDP_man-pages/draft/man2/sigsuspend.2 new file mode 100644 index 00000000..4eafb1b8 --- /dev/null +++ b/manual/LDP_man-pages/draft/man2/sigsuspend.2 @@ -0,0 +1,100 @@ +.\" Copyright (c) 2005 Michael Kerrisk +.\" based on earlier work by faith@cs.unc.edu and +.\" Mike Battersby +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. The author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\" 2005-09-15, mtk, Created new page by splitting off from sigaction.2 +.\" +.\"******************************************************************* +.\" +.\" This file was generated with po4a. Translate the source file. +.\" +.\"******************************************************************* +.\" +.\" Japanese Version Copyright (c) 2005 Akihiro MOTOKI all rights reserved. +.\" Translated 2005-10-03, Akihiro MOTOKI +.\" +.TH SIGSUSPEND 2 2019\-03\-06 Linux "Linux Programmer's Manual" +.SH 名前 +sigsuspend, rt_sigsuspend \- シグナルを待つ +.SH 書式 +\fB#include \fP +.PP +\fBint sigsuspend(const sigset_t *\fP\fImask\fP\fB);\fP +.PP +.RS -4 +glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): +.RE +.PP +.ad l +\fBsigsuspend\fP(): _POSIX_C_SOURCE +.ad b +.SH 説明 +\fBsigsuspend\fP() は、呼び出し元スレッドのシグナルマスクを \fImask\fP で指定されたマスクに一時的に置き換え、 +シグナルハンドラーの起動もしくはプロセスの終了がアクションとして 設定されたシグナルが配送されるまで、そのスレッドを停止する。 +.PP +シグナルがプロセスを終了させるものの場合、 \fBsigsuspend\fP() は返らない。シグナルが捕捉された場合、 +シグナルハンドラーの処理が終わった後に \fBsigsuspend\fP() は返り、シグナルマスクは \fBsigsuspend\fP() +が呼び出される前の状態に復元される。 +.PP +\fBSIGKILL\fP と \fBSIGSTOP\fP を禁止 (block) することはできない; これらのシグナルを \fImask\fP +に指定しても、そのスレッドのシグナルマスクは影響を受けない。 +.SH 返り値 +\fBsigsuspend\fP() は常に \-1 を返し、 \fIerrno\fP にエラーの原因を示す値 (通常は \fBEINTR\fP) を設定する。 +.SH エラー +.TP +\fBEFAULT\fP +\fImask\fP が指しているメモリーが、プロセスのアドレス空間の有効な部分ではない。 +.TP +\fBEINTR\fP +システムコールはシグナルにより割り込まれた。 \fBsignal\fP(7) を参照。 +.SH 準拠 +POSIX.1\-2001, POSIX.1\-2008. +.SH 注意 +\fBsigsuspend\fP() は、通常、クリティカルコードセクション (critical code section) の +実行中にシグナルが配送されるのを防止するために、 \fBsigprocmask\fP(2) と組み合わせて使用される。 まず最初に、呼び出し元は +\fBsigprocmask\fP(2) を使ってシグナルを禁止する。 クリティカルコードが完了すると、呼び出し元は \fBsigprocmask\fP(2) +が (\fIoldset\fP 引き数で) 返すシグナルマスクを指定して \fBsigsuspend\fP() +を呼び出すことで、クリティカルコード実行中に発生した シグナルを待つことができる。 +.PP +.\" +シグナル集合の操作に関する詳細は \fBsigsetops\fP(3) を参照のこと。 +.SS "C ライブラリとカーネルの違い" +.\" +The original Linux system call was named \fBsigsuspend\fP(). However, with the +addition of real\-time signals in Linux 2.2, the fixed\-size, 32\-bit +\fIsigset_t\fP type supported by that system call was no longer fit for +purpose. Consequently, a new system call, \fBrt_sigsuspend\fP(), was added to +support an enlarged \fIsigset_t\fP type. The new system call takes a second +argument, \fIsize_t sigsetsize\fP, which specifies the size in bytes of the +signal set in \fImask\fP. This argument is currently required to have the +value \fIsizeof(sigset_t)\fP (or the error \fBEINVAL\fP results). The glibc +\fBsigsuspend\fP() wrapper function hides these details from us, transparently +calling \fBrt_sigsuspend\fP() when the kernel provides it. +.SH 関連項目 +\fBkill\fP(2), \fBpause\fP(2), \fBsigaction\fP(2), \fBsignal\fP(2), \fBsigprocmask\fP(2), +\fBsigwaitinfo\fP(2), \fBsigsetops\fP(3), \fBsigwait\fP(3), \fBsignal\fP(7) +.SH この文書について +この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は +\%https://www.kernel.org/doc/man\-pages/ に書かれている。 diff --git a/manual/LDP_man-pages/draft/man2/sigwaitinfo.2 b/manual/LDP_man-pages/draft/man2/sigwaitinfo.2 index 75149a12..702ca51b 100644 --- a/manual/LDP_man-pages/draft/man2/sigwaitinfo.2 +++ b/manual/LDP_man-pages/draft/man2/sigwaitinfo.2 @@ -38,8 +38,7 @@ .\" .TH SIGWAITINFO 2 2017\-09\-15 Linux "Linux Programmer's Manual" .SH 名前 -sigwaitinfo, sigtimedwait, rt_sigtimedwait \- synchronously wait for queued -signals +sigwaitinfo, sigtimedwait, rt_sigtimedwait \- キューに入れられたシグナルを同期して待つ .SH 書式 .nf \fB#include \fP @@ -123,7 +122,7 @@ signal handler. .\" POSIX では \fBsigtimedwait\fP() の引き数 \fItimeout\fP の値を NULL にした場合の意味を未定義としている。 \fBsigwaitinfo\fP() を呼び出したのと同じ意味としてもよいことになっており、 実際 Linux ではこのように動作する。 -.SS "C library/kernel differences" +.SS "C ライブラリとカーネルの違い" Linux では、 \fBsigwaitinfo\fP() は \fBsigtimedwait\fP() を用いて実装されたライブラリ関数である。 .PP The glibc wrapper functions for \fBsigwaitinfo\fP() and \fBsigtimedwait\fP() diff --git a/manual/LDP_man-pages/draft/man2/tkill.2 b/manual/LDP_man-pages/draft/man2/tkill.2 index 8f312a87..850ff5cf 100644 --- a/manual/LDP_man-pages/draft/man2/tkill.2 +++ b/manual/LDP_man-pages/draft/man2/tkill.2 @@ -46,7 +46,7 @@ tkill, tgkill \- スレッドにシグナルを送る \fBint tgkill(int \fP\fItgid\fP\fB, int \fP\fItid\fP\fB, int \fP\fIsig\fP\fB);\fP .fi .PP -\fINote\fP: There is no glibc wrapper for \fBtkill\fP(); see NOTES. +\fI注\fP: \fBtkill\fP() には、glibc のラッパー関数はない。「注意」の節を参照。 .SH 説明 \fBtgkill\fP() はスレッドグループ \fItgid\fP に属するスレッド ID が \fItid\fP のスレッドにシグナル \fIsig\fP を送る。 (これに対し、 \fBkill\fP(2) は一つのプロセス (すなわち、スレッドグループ) にまとめてシグナルを 送るのにだけ利用できる。 @@ -105,15 +105,14 @@ Insufficient kernel memory was available and \fIsig\fP is a real\-time signal. \fBtkill\fP() は Linux 2.4.19 / 2.5.4 以降でサポートされ、 \fBtgkill\fP() は Linux 2.5.75 で追加された。 .PP -Library support for \fBtgkill\fP() was added to glibc in version 2.30. +\fBtgkill\fP() のライブラリでのサポートは glibc バージョン 2.30 で追加された。 .SH 準拠 \fBtkill\fP() と \fBtgkill\fP() は Linux 固有であり、 移植を想定したプログラムでは使用すべきではない。 .SH 注意 スレッドグループの説明については \fBclone\fP(2) の \fBCLONE_THREAD\fP の説明を参照のこと。 .PP -Glibc does not provide a wrapper for \fBtkill\fP(); call it using -\fBsyscall\fP(2). Before glibc 2.30, there was also no wrapper function for -\fBtgkill\fP(). +glibc は \fBtkill\fP() に対するラッパー関数を提供していない。 \fBsyscall\fP(2) を使用すること。 glibc 2.30 +より前では、 \fBtgkill\fP() に対するラッパー関数も存在しない。 .SH 関連項目 \fBclone\fP(2), \fBgettid\fP(2), \fBkill\fP(2), \fBrt_sigqueueinfo\fP(2) .SH この文書について diff --git a/manual/LDP_man-pages/draft/man2/wait.2 b/manual/LDP_man-pages/draft/man2/wait.2 new file mode 100644 index 00000000..c7959add --- /dev/null +++ b/manual/LDP_man-pages/draft/man2/wait.2 @@ -0,0 +1,453 @@ +.\" Copyright (c) 1993 by Thomas Koenig +.\" and Copyright (c) 2004 by Michael Kerrisk +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. The author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\" Modified Sat Jul 24 13:30:06 1993 by Rik Faith +.\" Modified Sun Aug 21 17:42:42 1994 by Rik Faith +.\" (Thanks to Koen Holtman ) +.\" Modified Wed May 17 15:54:12 1995 by Rik Faith +.\" To remove *'s from status in macros (Thanks to Michael Shields). +.\" Modified as suggested by Nick Duffek , aeb, 960426 +.\" Modified Mon Jun 23 14:09:52 1997 by aeb - add EINTR. +.\" Modified Thu Nov 26 02:12:45 1998 by aeb - add SIGCHLD stuff. +.\" Modified Mon Jul 24 21:37:38 2000 by David A. Wheeler +.\" - noted thread issues. +.\" Modified 26 Jun 01 by Michael Kerrisk +.\" Added __WCLONE, __WALL, and __WNOTHREAD descriptions +.\" Modified 2001-09-25, aeb +.\" Modified 26 Jun 01 by Michael Kerrisk, +.\" Updated notes on setting disposition of SIGCHLD to SIG_IGN +.\" 2004-11-11, mtk +.\" Added waitid(2); added WCONTINUED and WIFCONTINUED() +.\" Added text on SA_NOCLDSTOP +.\" Updated discussion of SA_NOCLDWAIT to reflect 2.6 behavior +.\" Much other text rewritten +.\" 2005-05-10, mtk, __W* flags can't be used with waitid() +.\" 2008-07-04, mtk, removed erroneous text about SA_NOCLDSTOP +.\" +.\"******************************************************************* +.\" +.\" This file was generated with po4a. Translate the source file. +.\" +.\"******************************************************************* +.\" +.\" Japanese Version Copyright (c) 1997 HANATAKA Shinya all rights reserved. +.\" Japanese Version Copyright (c) 2005 Akihiro MOTOKI all rights reserved. +.\" Translated 1997-03-04, HANATAKA Shinya +.\" Modified 2000-09-23, HANATAKA Shinya +.\" Updated 2001-06-25, Kentaro Shirakata +.\" Updated 2001-10-15, Kentaro Shirakata +.\" Updated 2001-12-13, Kentaro Shirakata +.\" Updated 2002-10-21, Kentaro Shirakata +.\" Updated 2003-01-27, Kentaro Shirakata +.\" Updated 2003-09-12, Kentaro Shirakata +.\" Updated 2005-03-19, Akihiro MOTOKI +.\" Updated 2005-12-26, Akihiro MOTOKI +.\" Updated 2008-07-31, Akihiro MOTOKI, LDP v3.05 +.\" Updated 2013-05-06, Akihiro MOTOKI +.\" +.TH WAIT 2 2020\-11\-01 Linux "Linux Programmer's Manual" +.SH 名前 +wait, waitpid, waitid \- プロセスの状態変化を待つ +.SH 書式 +\fB#include \fP +.br +\fB#include \fP +.PP +\fBpid_t wait(int *\fP\fIwstatus\fP\fB);\fP +.PP +\fBpid_t waitpid(pid_t \fP\fIpid\fP\fB, int *\fP\fIwstatus\fP\fB, int \fP\fIoptions\fP\fB);\fP +.PP +\fBint waitid(idtype_t \fP\fIidtype\fP\fB, id_t \fP\fIid\fP\fB, siginfo_t *\fP\fIinfop\fP\fB, int \fP\fIoptions\fP\fB);\fP + /* これは glibc と POSIX のインターフェイスである。 + 生のシステムコールについての情報は「注意」の節を参照。 */ +.PP +.RS -4 +glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): +.RE +.PP +.ad l +.PD 0 +\fBwaitid\fP(): +.RS 4 +.\" (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) +glibc 2.26 以降: +_XOPEN_SOURCE >= 500 || + _POSIX_C_SOURCE\ >=\ 200809L +.br +glibc 2.25 以前: + _XOPEN_SOURCE + || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L + || /* Glibc versions <= 2.19: */ _BSD_SOURCE +.RE +.PD +.ad +.SH 説明 +これらのシステムコールはいずれも、呼び出し元プロセスの子プロセスの 状態変化を待ち、状態が変化したその子プロセスの情報を取得するのに 使用される。 +状態変化とは以下のいずれかである: 子プロセスの終了、シグナルによる子プロセスの停止、 シグナルによる子プロセスの再開。 +子プロセスが終了した場合は、wait を実行することで、 システムがその子プロセスに関連するリソースを解放できるようになる。 wait +が実行されなかった場合には、終了した子プロセスは 「ゾンビ」状態で残り続ける (下記の注意の章を参照のこと)。 +.PP +子プロセスの状態変化がすでに発生していた場合、これらのコールは すぐに復帰する。それ以外の場合は、子プロセスの状態変化が起こるか、 +シグナルハンドラーによりシステムコールが中断されるまで、 停止 (block) する (後者は、 \fBsigaction\fP(2) の +\fBSA_RESTART\fP フラグによりシステムコールが自動的に再スタートするようになっていない 場合の動作である)。 +以下の説明では、状態変化が起こったがこれらのシステムコールのいずれかに よって待たれていない子プロセスを \fIwaitable\fP (待ち可能) と呼ぶ。 +.SS "wait() と waitpid()" +\fBwait\fP() システムコールは、子プロセスのいずれかが終了するまで 呼び出し元のスレッドの実行を一時停止する。 呼び出し +\fIwait(&wstatus)\fP は以下と等価である: +.PP +.in +4n +.EX +waitpid(\-1, &wstatus, 0); +.EE +.in +.PP +\fBwaitpid\fP() システムコールは、 \fIpid\fP 引き数で指定した子プロセスの状態変化が起こるまで、 +呼び出し元のスレッドの実行を一時停止する。デフォルトでは、 \fBwaitpid\fP() は子プロセスの終了だけを待つが、この動作は \fIoptions\fP +引き数により変更可能である。 +.PP +\fIpid\fP に指定できる値は以下の通り: +.IP "< \-1" +プロセスグループID が \fIpid\fP の絶対値に等しい子プロセスのいずれかが終了するまでを待つ。 +.IP \-1 +子プロセスのどれかが終了するまで待つ。 +.IP 0 +プロセスグループ ID が、\fBwaitpid\fP() が呼ばれた時点での呼び出し元のプロセスのプロセスグループ ID と等しい子プロセスを待つ。 +.IP "> 0" +プロセスID が \fIpid\fP に等しい子プロセスを待つ。 +.PP +\fIoptions\fP の値は次の定数の 0 個以上の論理和である: +.TP +\fBWNOHANG\fP +状態変化が起こった子プロセスがない場合にすぐに復帰する。 +.TP +\fBWUNTRACED\fP +子プロセスが停止した場合にも復帰する (子プロセスが \fBptrace\fP(2) でトレースされている場合は除く)。 +このオプションが指定されていない場合でも、停止したプロセスが 「トレース (traced)」されていれば、子プロセスの状態が報告される。 +.TP +\fBWCONTINUED\fP (Linux 2.6.10 以降) +停止した子プロセスが \fBSIGCONT\fP の配送により再開した場合にも復帰する。 +.PP +(Linux 専用オプションについては後述する) +.PP +\fIwstatus\fP が NULL でなければ、 \fBwait\fP() や \fBwaitpid\fP() は \fIstatus\fP で指す \fIint\fP +に状態情報を格納する。 この整数は以下のマクロを使って検査できる。 (これらのマクロの引き数には、 \fBwait\fP() や \fBwaitpid\fP() +が書き込んだ整数そのものを指定する。ポインターではない!) +.TP +\fBWIFEXITED(\fP\fIwstatus\fP\fB)\fP +子プロセスが正常に終了した場合に真を返す。 「正常に」とは、 \fBexit\fP(3) か \fB_exit\fP(2) が呼び出された場合、もしくは +main() から復帰した場合である。 +.TP +\fBWEXITSTATUS(\fP\fIwstatus\fP\fB)\fP +子プロセスの終了ステータスを返す。 終了ステータスは \fIstatus\fP 引き数の下位 8ビットで構成されており、 \fBexit\fP(3) や +\fB_exit\fP(2) の呼び出し時に渡された値、もしくは main() の return 文の 引き数として指定された値である。 +このマクロを使用するのは \fBWIFEXITED\fP が真を返した場合だけにすべきである。 +.TP +\fBWIFSIGNALED(\fP\fIwstatus\fP\fB)\fP +子プロセスがシグナルにより終了した場合に真を返す。 +.TP +\fBWTERMSIG(\fP\fIwstatus\fP\fB)\fP +子プロセス終了の原因となったシグナルの番号を返す。 このマクロを使用するのは \fBWIFSIGNALED\fP が真を返した場合だけにすべきである。 +.TP +\fBWCOREDUMP(\fP\fIwstatus\fP\fB)\fP +returns true if the child produced a core dump (see \fBcore\fP(5)). This macro +should be employed only if \fBWIFSIGNALED\fP returned true. +.IP +This macro is not specified in POSIX.1\-2001 and is not available on some +UNIX implementations (e.g., AIX, SunOS). Therefore, enclose its use inside +\fI#ifdef WCOREDUMP ... #endif\fP. +.TP +\fBWIFSTOPPED(\fP\fIwstatus\fP\fB)\fP +子プロセスがシグナルの配送により停止した場合に真を返す。 これが真になるのは、システムコールが \fBWUNTRACED\fP +を指定して呼び出された場合か、子プロセスがトレースされている場合 (\fBptrace\fP(2) 参照) だけである。 +.TP +\fBWSTOPSIG(\fP\fIwstatus\fP\fB)\fP +子プロセスを停止させたシグナルの番号を返す。 このマクロを使用するのは \fBWIFSTOPPED\fP が 0 以外を返した場合だけにすべきである。 +.TP +\fBWIFCONTINUED(\fP\fIwstatus\fP\fB)\fP +(Linux 2.6.10 以降) 子プロセスが \fBSIGCONT\fP の配送により再開した場合に真を返す。 +.SS waitid() +\fBwaitid\fP() システムコール (Linux 2.6.9 以降で利用可能) を使うと、 +子プロセスのどの状態変化を待つかについてより細かな制御ができる。 +.PP +引き数 \fIidtype\fP と \fIid\fP でどの子プロセスを待つかを選択する: +.IP "\fIidtype\fP == \fBP_PID\fP" +プロセスID が \fIid\fP と一致する子プロセスを待つ。 +.IP "\fIidtype\fP == \fBP_PIDFD\fP (since Linux 5.4)" +.\" commit 3695eae5fee0605f316fbaad0b9e3de791d7dfaf +Wait for the child referred to by the PID file descriptor specified in +\fIid\fP. (See \fBpidfd_open\fP(2) for further information on PID file +descriptors.) +.IP "\fIidtype\fP == \fBP_PGID\fP" +.\" commit 821cc7b0b205c0df64cce59aacc330af251fa8f7 +Wait for any child whose process group ID matches \fIid\fP. Since Linux 5.4, +if \fIid\fP is zero, then wait for any child that is in the same process group +as the caller's process group at the time of the call. +.IP "\fIidtype\fP == \fBP_ALL\fP" +子プロセス全部を対象に待つ。 \fIid\fP は無視される。 +.PP +子プロセスのどの状態変化を待つかは以下のフラグで指定する (\fIoptions\fP には 1個以上のフラグの論理和をとって指定する): +.TP +\fBWEXITED\fP +子プロセスの終了を待つ。 +.TP +\fBWSTOPPED\fP +子プロセスがシグナルの配送により停止するのを待つ。 +.TP +\fBWCONTINUED\fP +(停止していた) 子プロセスが \fBSIGCONT\fP が配送されて再開するのを待つ。 +.PP +さらに以下のフラグを論理和の形で \fIoptions\fP に指定できる: +.TP +\fBWNOHANG\fP +\fBwaitpid\fP() と同様。 +.TP +\fBWNOWAIT\fP +waitable 状態のプロセスをそのままにする。この後で wait コールを 使って、同じ子プロセスの状態情報をもう一度取得することができる。 +.PP +成功した場合には、 \fBwaitid\fP() は \fIinfop\fP が指す \fIsiginfo_t\fP 構造体の以下のフィールドを設定する: +.TP +\fIsi_pid\fP +子プロセスのプロセスID。 +.TP +\fIsi_uid\fP +子プロセスの実ユーザーID (このフィールドは他のほとんどの実装では設定されない)。 +.TP +\fIsi_signo\fP +常に \fBSIGCHLD\fP が設定される。 +.TP +\fIsi_status\fP +\fB_exit\fP(2) (か \fBexit\fP(3)) に指定された子プロセスの終了ステータス、もしくは +子プロセスの終了、停止、再開の原因となったシグナルが設定される。 このフィールドをどう解釈するかは、 \fIsi_code\fP +フィールドを参照して決めることができる。 +.TP +\fIsi_code\fP +以下のいずれかが設定される: \fBCLD_EXITED\fP (子プロセスが \fB_exit\fP(2) を呼び出した); \fBCLD_KILLED\fP +(シグナルにより子プロセスが kill された); \fBCLD_DUMPED\fP (シグナルにより子プロセスが kill され、コアダンプが行われた); +\fBCLD_STOPPED\fP (シグナルにより子プロセスが停止した); \fBCLD_TRAPPED\fP +(トレースされていた子プロセスがトラップを受信した); \fBCLD_CONTINUED\fP (\fBSIGCONT\fP により子プロセスが再開された)。 +.PP +If \fBWNOHANG\fP was specified in \fIoptions\fP and there were no children in a +waitable state, then \fBwaitid\fP() returns 0 immediately and the state of the +\fIsiginfo_t\fP structure pointed to by \fIinfop\fP depends on the +implementation. To (portably) distinguish this case from that where a child +was in a waitable state, zero out the \fIsi_pid\fP field before the call and +check for a nonzero value in this field after the call returns. +.PP +.\" POSIX.1-2001 leaves this possibility unspecified; most +.\" implementations (including Linux) zero out the structure +.\" in this case, but at least one implementation (AIX 5.1) +.\" does not -- MTK Nov 04 +POSIX.1\-2008 Technical Corrigendum 1 (2013) adds the requirement that when +\fBWNOHANG\fP is specified in \fIoptions\fP and there were no children in a +waitable state, then \fBwaitid\fP() should zero out the \fIsi_pid\fP and +\fIsi_signo\fP fields of the structure. On Linux and other implementations +that adhere to this requirement, it is not necessary to zero out the +\fIsi_pid\fP field before calling \fBwaitid\fP(). However, not all +implementations follow the POSIX.1 specification on this point. +.SH 返り値 +\fBwait\fP(): 成功すると、終了した子プロセスのプロセスID を返す。 エラーの場合 \-1 を返す。 +.PP +\fBwaitpid\fP(): 成功すると、状態が変化した子プロセスのプロセスID を返す。 \fBWNOHANG\fP が指定されていて、 \fIpid\fP +で指示された子プロセスが一つ以上存在するが、どの子プロセスでも 状態変化が起こっていなかった場合は、 0 を返す。 エラーの場合 \-1 を返す。 +.PP +.\" FIXME As reported by Vegard Nossum, if infop is NULL, then waitid() +.\" returns the PID of the child. Either this is a bug, or it is intended +.\" behavior that needs to be documented. See my Jan 2009 LKML mail +.\" "waitid() return value strangeness when infop is NULL". +\fBwaitid\fP(): 成功すると 0 を返す。 \fBWNOHANG\fP が指定されていて、 \fIpid\fP +で指示された子プロセスで状態変化が起こっていなかった場合にも 0 を返す。 +.PP +エラーの場合 \-1 を返す。 エラーの場合、これらのシステムコールはいずれも \fIerrno\fP に適切な値を設定する。 +.SH エラー +.TP +\fBECHILD\fP +(\fBwait\fP() の場合) 呼び出し元プロセスには、wait を行っていない子プロセスはない。 +.TP +\fBECHILD\fP +(\fBwaitpid\fP() か \fBwaitid\fP() の場合) \fIpid\fP (\fBwaitpid\fP()) か \fIidtype\fP と +\fIid\fP (\fBwaitid\fP()) で指定したプロセスが存在しないか、呼び出し元プロセスの子プロセスでない (\fBSIGCHLD\fP の動作に +\fBSIG_IGN\fP を設定した場合には、自分自身の子プロセスでも起こりうる。 スレッドに関しては「Linux での注意」の節も参照すること)。 +.TP +\fBEINTR\fP +\fBWNOHANG\fP が設定されておらず、禁止 (block) されていないシグナルや \fBSIGCHLD\fP を受信した。 \fBsignal\fP(7) +参照。 +.TP +\fBEINVAL\fP +\fIoptions\fP 引き数が不正である。 +.SH 準拠 +SVr4, 4.3BSD, POSIX.1\-2001. +.SH 注意 +A child that terminates, but has not been waited for becomes a "zombie". +The kernel maintains a minimal set of information about the zombie process +(PID, termination status, resource usage information) in order to allow the +parent to later perform a wait to obtain information about the child. As +long as a zombie is not removed from the system via a wait, it will consume +a slot in the kernel process table, and if this table fills, it will not be +possible to create further processes. If a parent process terminates, then +its "zombie" children (if any) are adopted by \fBinit\fP(1), (or by the +nearest "subreaper" process as defined through the use of the \fBprctl\fP(2) +\fBPR_SET_CHILD_SUBREAPER\fP operation); \fBinit\fP(1) automatically performs a +wait to remove the zombies. +.PP +POSIX.1\-2001 では以下のように規定されている。 \fBSIGCHLD\fP の動作が \fBSIG_IGN\fP に設定されたか、 \fBSIGCHLD\fP +に対して \fBSA_NOCLDWAIT\fP フラグが設定された場合 (\fBsigaction\fP(2) 参照)、終了した子プロセスはゾンビにはならず、 +\fBwait\fP() や \fBwaitpid\fP() の呼び出しは全ての子プロセスが終了するまで停止し、 子プロセスが全部終了した後 \fIerrno\fP +に \fBECHILD\fP を設定して失敗する。 (もともとの POSIX 標準は \fBSIGCHLD\fP に \fBSIG_IGN\fP +を設定した場合の振る舞いを未規定のままにしている。 \fBSIGCHLD\fP のデフォルトの動作が「無視」であるにもかかわらず、 \fBSIGCHLD\fP +の動作として \fBSIG_IGN\fP を明示的に設定した場合にはゾンビプロセスの子プロセスの扱いが 異なる点に注意すること。) +.PP +Linux 2.6 はこの仕様に準拠している。 しかし、Linux 2.4 (とそれ以前のバージョン) はそうではない: \fBSIGCHLD\fP +が無視される状態で \fBwait\fP() または \fBwaitpid\fP() が呼び出された場合、 \fBSIGCHLD\fP +が無視されていないかのように振る舞う。 つまり、呼び出しによって次の子プロセスの終了までブロックされ、 終了した子プロセスの PID と状態が返される。 +.SS "Linux での注意" +Linux カーネルでは、カーネルによってスケジュールされるスレッドは プロセスと明確に区別できる構成要素ではない。スレッドは Linux 固有の +\fBclone\fP(2) システムコールを使用して生成されるプロセスに過ぎない。 移植性のある \fBpthread_create\fP(3) +コールのような他のルーチンは \fBclone\fP(2) を使用して実装されている; これらでは \fBwaitid\fP() を使うことはできない。 +Linux 2.4 より前では、スレッドは単に特殊なプロセスであったので、 例え同じスレッドグループであっても、 +あるスレッドが別のスレッドの子プロセスが終了するのを待つことは出来なかった。 しかし、POSIX ではこのような機能を規定しており、 Linux 2.4 +以降では、あるスレッドが同じスレッドグループの他のスレッドの 子プロセスが終了するのを待つことができるようになった。 +そして将来はこれがデフォルトの動作になるであろう。 +.PP +.\" commit 91c4e8ea8f05916df0c8a6f383508ac7c9e10dba +The following Linux\-specific \fIoptions\fP are for use with children created +using \fBclone\fP(2); they can also, since Linux 4.7, be used with \fBwaitid\fP(): +.TP +\fB__WCLONE\fP +.\" since 0.99pl10 +"clone" な子プロセスだけを待つ。 指定されなかった場合は非 "clone" な子プロセスだけを待つ ("clone" +な子プロセスは、終了時に親プロセスへ全くシグナルを送らないか、 \fBSIGCHLD\fP 以外のシグナルを送る)。 このオプションは \fB__WALL\fP +も指定された場合は無視される。 +.TP +\fB__WALL\fP (Linux 2.4 以降) +.\" since patch-2.3.48 +"clone" であるかないかに関わらず、 全ての子プロセスを待つ。 +.TP +\fB__WNOTHREAD\fP (Linux 2.4 以降) +.\" since patch-2.4.0-test8 +同じスレッドグループの他のスレッドの子プロセスは待たない。 Linux 2.4 より前ではデフォルトであった。 +.PP +.\" commit bf959931ddb88c4e4366e96dd22e68fa0db9527c +.\" prevents cases where an unreapable zombie is created if +.\" /sbin/init doesn't use __WALL. +Since Linux 4.7, the \fB__WALL\fP flag is automatically implied if the child is +being ptraced. +.SS "C ライブラリとカーネルの違い" +\fBwait\fP() is actually a library function that (in glibc) is implemented as +a call to \fBwait4\fP(2). +.PP +.\" e.g., i386 has the system call, but not x86-64 +On some architectures, there is no \fBwaitpid\fP() system call; instead, this +interface is implemented via a C library wrapper function that calls +\fBwait4\fP(2). +.PP +生の \fBwaitid\fP() システムコールは \fIstruct rusage\ *\fP 型の第 5 引数を取る。 この引数が NULL 以外の場合、 +この引数が子プロセスのリソース使用状況を返すのに使用される。 これは \fBwait4\fP(2) と同じ方法である。 詳細は \fBgetrusage\fP(2) +を参照。 +.SH バグ +POSIX.1\-2008 によると、 \fBwaitid\fP() を呼び出すアプリケーションは、 \fIinfop\fP が \fIsiginfo_t\fP +構造体を指していること (つまり \fIinfop\fP が NULL でないポインターであること) を保証しなければならない。 Linux では、 +\fIinfop\fP が NULL の場合、 \fBwaitid\fP() は成功し、wait している子プロセスのプロセス ID を返す。 +アプリケーションは、この食い違った、非標準で、不必要な機能に依存しないようにすべきである。 +.SH 例 +.\" fork.2 refers to this example program. +以下のプログラムは、 \fBfork\fP(2) と \fBwaitpid\fP() の使用方法の例を示している。 このプログラムでは子プロセスを生成する。 +コマンドライン引き数が指定されなかったときは、 子プロセスは \fBpause\fP(2) を使ってその実行を一時停止し、ユーザーがその子プロセスに +シグナルを送信できるようにする。 コマンドライン引き数が指定された場合は、 子プロセスは直ちに終了し、 +コマンドラインで指定された整数を終了ステータスとして使用する。 親プロセスは、 \fBwaitpid\fP() を使って子プロセスを監視し、 wait +のステータス値を上記の W*() マクロを使って解析するという ループを実行する。 +.PP +以下のシェルのセッションはこのプログラムの使用例を示したものである。 +.PP +.in +4n +.EX +$\fB ./a.out &\fP +Child PID is 32360 +[1] 32359 +$\fB kill \-STOP 32360\fP +stopped by signal 19 +$\fB kill \-CONT 32360\fP +continued +$\fB kill \-TERM 32360\fP +killed by signal 15 +[1]+ Done ./a.out +$ +.EE +.in +.SS プログラムのソース +\& +.EX +#include +#include +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + pid_t cpid, w; + int wstatus; + + cpid = fork(); + if (cpid == \-1) { + perror("fork"); + exit(EXIT_FAILURE); + } + + if (cpid == 0) { /* Code executed by child */ + printf("Child PID is %jd\en", (intmax_t) getpid()); + if (argc == 1) + pause(); /* Wait for signals */ + _exit(atoi(argv[1])); + + } else { /* Code executed by parent */ + do { + w = waitpid(cpid, &wstatus, WUNTRACED | WCONTINUED); + if (w == \-1) { + perror("waitpid"); + exit(EXIT_FAILURE); + } + + if (WIFEXITED(wstatus)) { + printf("exited, status=%d\en", WEXITSTATUS(wstatus)); + } else if (WIFSIGNALED(wstatus)) { + printf("killed by signal %d\en", WTERMSIG(wstatus)); + } else if (WIFSTOPPED(wstatus)) { + printf("stopped by signal %d\en", WSTOPSIG(wstatus)); + } else if (WIFCONTINUED(wstatus)) { + printf("continued\en"); + } + } while (!WIFEXITED(wstatus) && !WIFSIGNALED(wstatus)); + exit(EXIT_SUCCESS); + } +} +.EE +.SH 関連項目 +\fB_exit\fP(2), \fBclone\fP(2), \fBfork\fP(2), \fBkill\fP(2), \fBptrace\fP(2), +\fBsigaction\fP(2), \fBsignal\fP(2), \fBwait4\fP(2), \fBpthread_create\fP(3), +\fBcore\fP(5), \fBcredentials\fP(7), \fBsignal\fP(7) +.SH この文書について +この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は +\%https://www.kernel.org/doc/man\-pages/ に書かれている。 diff --git a/manual/LDP_man-pages/draft/man2/wait4.2 b/manual/LDP_man-pages/draft/man2/wait4.2 new file mode 100644 index 00000000..7943e808 --- /dev/null +++ b/manual/LDP_man-pages/draft/man2/wait4.2 @@ -0,0 +1,152 @@ +.\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de) +.\" and Copyright (c) 2004 by Michael Kerrisk +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. The author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\" Modified Sat Jul 24 13:32:44 1993 by Rik Faith (faith@cs.unc.edu) +.\" Modified Mon Jun 23 14:09:52 1997 by aeb - add EINTR. +.\" Modified Tue Jul 7 12:26:42 1998 by aeb - changed return value wait3 +.\" Modified 2004-11-11, Michael Kerrisk +.\" Rewrote much of this page, and removed much duplicated text, +.\" replacing with pointers to wait.2 +.\" +.\"******************************************************************* +.\" +.\" This file was generated with po4a. Translate the source file. +.\" +.\"******************************************************************* +.\" +.\" Japanese Version Copyright (c) 1997,1998 HANATAKA Shinya +.\" all rights reserved. +.\" Translated 1997-03-04, HANATAKA Shinya +.\" Modified 1997-09-28, HANATAKA Shinya +.\" Modified 2001-08-17, HANATAKA Shinya +.\" Updated 2001-12-13, Kentaro Shirakata +.\" Updated 2003-09-12, Kentaro Shirakata +.\" Updated 2005-03-04, Akihiro MOTOKI +.\" Updated 2013-05-06, Akihiro MOTOKI +.\" +.TH WAIT4 2 2020\-06\-09 Linux "Linux Programmer's Manual" +.SH 名前 +wait3, wait4 \- BSD スタイルでプロセスの状態変化を待つ +.SH 書式 +.nf +\fB#include \fP +\fB#include \fP +\fB#include \fP +\fB#include \fP +.PP +\fBpid_t wait3(int *\fP\fIwstatus\fP\fB, int \fP\fIoptions\fP\fB,\fP +\fB struct rusage *\fP\fIrusage\fP\fB);\fP +.PP +\fBpid_t wait4(pid_t \fP\fIpid\fP\fB, int *\fP\fIwstatus\fP\fB, int \fP\fIoptions\fP\fB,\fP +\fB struct rusage *\fP\fIrusage\fP\fB);\fP +.fi +.PP +.RS -4 +glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): +.RE +.PP +.ad l +.\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED +\fBwait3\fP(): + Since glibc 2.26: + _DEFAULT_SOURCE || + (_XOPEN_SOURCE\ >=\ 500 && + ! (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)) + From glibc 2.19 to 2.25: + _DEFAULT_SOURCE || _XOPEN_SOURCE\ >=\ 500 + Glibc 2.19 and earlier: + _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 +.br +\fBwait4\fP(): + Since glibc 2.19: + _DEFAULT_SOURCE + Glibc 2.19 and earlier: + _BSD_SOURCE +.ad +.SH 説明 +These functions are nonstandard; in new programs, the use of \fBwaitpid\fP(2) +or \fBwaitid\fP(2) is preferable. +.PP +システムコール \fBwait3\fP() と \fBwait4\fP() は \fBwaitpid\fP(2) +と同様の動作をする。それに加え、子プロセスのリソース使用状況の情報を \fIrusage\fP が指す構造体に入れて返す。 +.PP +\fIrusage\fP を使用する点を除けば、次の \fBwait3\fP() の呼び出し +.PP +.in +4n +.EX +wait3(wstatus, options, rusage); +.EE +.in +.PP +は以下と等価である。 +.PP +.in +4n +.EX +waitpid(\-1, wstatus, options); +.EE +.in +.PP +同様に、次の \fBwait4\fP() の呼び出し +.PP +.in +4n +.EX +wait4(pid, wstatus, options, rusage); +.EE +.in +.PP +は以下と等価である。 +.PP +.in +4n +.EX +waitpid(pid, wstatus, options); +.EE +.in +.PP +言い換えると、 \fBwait3\fP() は全ての子プロセスを対象に待つが、 \fBwait4\fP() では特定の子プロセス (複数可) +を選んで待つことができる。 +.PP +\fIrusage\fP が NULL でない場合、 \fIrusage\fP が指す \fIrusage 構造体\fP には子プロセスのアカウント情報が格納される。 +詳しくは \fBgetrusage\fP(2) を参照のこと。 +.SH 返り値 +\fBwaitpid\fP(2) と同様。 +.SH エラー +\fBwaitpid\fP(2) と同様。 +.SH 準拠 +4.3BSD. +.PP +SUSv1 には \fBwait3\fP() の規定があった。 SUSv2 には \fBwait3\fP() が含まれていたが、「過去の名残 +(LEGACY)」となっていた。 SUSv3 では \fBwait3\fP() は削除された。 +.SH 注意 +現在では \fI\fP をインクルードする必要はないが、インクルードしておくと 移植性を高めることができる (実際には +\fI\fP で \fIrusage\fP 構造体が定義されているが、そのフィールドで使用されている +\fIstruct timeval\fP 型は \fI\fP で定義されている)。 +.SS "C ライブラリとカーネルの違い" +Linux では、 \fBwait3\fP() はライブラリ関数であり、 \fBwait4\fP() システムコールを使って実装されている。 +.SH 関連項目 +\fBfork\fP(2), \fBgetrusage\fP(2), \fBsigaction\fP(2), \fBsignal\fP(2), \fBwait\fP(2), +\fBsignal\fP(7) +.SH この文書について +この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は +\%https://www.kernel.org/doc/man\-pages/ に書かれている。 diff --git a/manual/LDP_man-pages/draft/man3/bsd_signal.3 b/manual/LDP_man-pages/draft/man3/bsd_signal.3 index e4a342c7..6fb7d2a7 100644 --- a/manual/LDP_man-pages/draft/man3/bsd_signal.3 +++ b/manual/LDP_man-pages/draft/man3/bsd_signal.3 @@ -50,7 +50,7 @@ glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参 \fBbsd_signal\fP(): .RS 4 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED -Since glibc 2.26: +glibc 2.26 以降: _XOPEN_SOURCE >= 500 && ! (_POSIX_C_SOURCE\ >=\ 200809L) .br diff --git a/manual/LDP_man-pages/draft/man3/gsignal.3 b/manual/LDP_man-pages/draft/man3/gsignal.3 index 52b0e6a9..dbc2d5ed 100644 --- a/manual/LDP_man-pages/draft/man3/gsignal.3 +++ b/manual/LDP_man-pages/draft/man3/gsignal.3 @@ -61,18 +61,14 @@ glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参 Linux ではこれらの関数を使用しないこと。 過去に間違いがあり、Linux では \fBgsignal\fP() と \fBssignal\fP() はそれぞれ \fBraise\fP(3) と \fBsignal\fP(2) の別名になっている。 .PP -Elsewhere, on System V\-like systems, these functions implement software -signaling, entirely independent of the classical \fBsignal\fP(2) and -\fBkill\fP(2) functions. The function \fBssignal\fP() defines the action to -take when the software signal with number \fIsignum\fP is raised using the -function \fBgsignal\fP(), and returns the previous such action or \fBSIG_DFL\fP. -The function \fBgsignal\fP() does the following: if no action (or the action -\fBSIG_DFL\fP) was specified for \fIsignum\fP, then it does nothing and returns -0. If the action \fBSIG_IGN\fP was specified for \fIsignum\fP, then it does -nothing and returns 1. Otherwise, it resets the action to \fBSIG_DFL\fP and -calls the action function with argument \fIsignum\fP, and returns the value -returned by that function. The range of possible values \fIsignum\fP varies -(often 1\(en15 or 1\(en17). +一方、System V 風のシステムでは、これらの関数で、 従来の \fBsignal\fP(2) や \fBkill\fP(2) の関数群とは完全に独立な、 +ソフトウェアシグナリングを実現している。 \fBssignal\fP() 関数は、番号 \fIsignum\fP のソフトウェアシグナルが +\fBgsignal\fP() 関数を使って発生された時にとるべきアクションを定義する。 \fBgsignal\fP() +の返り値は、一つ前に指定されていたアクション、もしくは \fBSIG_DFL\fP である。 \fBgsignal\fP() は以下のような動作を行う: +\fIsignum\fP に対してアクションが指定されていないか、アクション \fBSIG_DFL\fP が指定されていた場合、何もせずに 0 を返す。 +\fIsignum\fP に対して アクション \fBSIG_IGN\fP が指定されていた場合、何もせずに 1 を返す。 それ以外の場合、アクションを +\fBSIG_DFL\fP にリセットし、引き数に \fIsignum\fP を指定してアクション関数を呼び出して、アクション関数の返り値を返す。 +\fIsignum\fP がとり得る値の範囲は実装により異なる (多くの場合 1〜15 か 1〜17 である)。 .SH 属性 この節で使用されている用語の説明については、 \fBattributes\fP(7) を参照。 .TS @@ -90,9 +86,9 @@ T} Thread safety MT\-Safe sigintr .sp 1 .SH 準拠 .\" Linux libc and -These functions are available under AIX, DG/UX, HP\-UX, SCO, Solaris, Tru64. -They are called obsolete under most of these systems, and are broken under -glibc. Some systems also have \fBgsignal_r\fP() and \fBssignal_r\fP(). +これらの関数は、AIX, DG/UX, HP\-UX, SCO, Solaris, Tru64 で使用可能である。 +これらのシステムのほとんどで廃止されたことになっており、 glibc では正しく実装されていない。 \fBgsignal_r\fP() と +\fBssignal_r\fP() が実装されているシステムもある。 .SH 関連項目 \fBkill\fP(2), \fBsignal\fP(2), \fBraise\fP(3) .SH この文書について diff --git a/manual/LDP_man-pages/draft/man3/killpg.3 b/manual/LDP_man-pages/draft/man3/killpg.3 new file mode 100644 index 00000000..523ebcdf --- /dev/null +++ b/manual/LDP_man-pages/draft/man3/killpg.3 @@ -0,0 +1,105 @@ +.\" Copyright (c) 1980, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" %%%LICENSE_START(BSD_4_CLAUSE_UCB) +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" %%%LICENSE_END +.\" +.\" @(#)killpg.2 6.5 (Berkeley) 3/10/91 +.\" +.\" Modified Fri Jul 23 21:55:01 1993 by Rik Faith +.\" Modified Tue Oct 22 08:11:14 EDT 1996 by Eric S. Raymond +.\" Modified 2004-06-16 by Michael Kerrisk +.\" Added notes on CAP_KILL +.\" Modified 2004-06-21 by aeb +.\" +.\"******************************************************************* +.\" +.\" This file was generated with po4a. Translate the source file. +.\" +.\"******************************************************************* +.TH KILLPG 3 2020\-06\-09 Linux "Linux Programmer's Manual" +.SH 名前 +killpg \- シグナルをプロセスグループに送る +.SH 書式 +\fB#include \fP +.PP +\fBint killpg(int \fP\fIpgrp\fP\fB, int \fP\fIsig\fP\fB);\fP +.PP +.RS -4 +glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): +.RE +.ad l +.TP 4 +\fBkillpg\fP(): +.\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED +_XOPEN_SOURCE\ >=\ 500 + || /* Since glibc 2.19: */ _DEFAULT_SOURCE + || /* Glibc versions <= 2.19: */ _BSD_SOURCE +.ad +.SH 説明 +\fBkillpg\fP() は \fIsig\fP で指定したシグナルを \fIpgrp\fP で指定したプロセスグループに送る。 シグナルの定義の一覧は +\fBsignal\fP(7) を参照のこと。 +.PP +引き数 \fIpgrp\fP に 0 を指定した場合には \fBkillpg\fP() は呼び出し元のプロセスが属しているプロセスグループに対してシグナルを送る。 +(POSIX では以下のように記述されている: \fIpgrp\fP が 1 以下である場合、動作は未定義である。) +.PP +For the permissions required to send a signal to another process, see +\fBkill\fP(2). +.SH 返り値 +成功した場合、0 が返される。エラーが発生した場合、\-1 が返され、 \fIerrno\fP が適切に設定される。 +.SH エラー +.TP +\fBEINVAL\fP +\fIsig\fP で指定された値は無効なシグナル番号である。 +.TP +\fBEPERM\fP +The process does not have permission to send the signal to any of the target +processes. For the required permissions, see \fBkill\fP(2). +.TP +\fBESRCH\fP +\fIpgrp\fP で指定されたプロセスグループに属するプロセスが存在しなかった。 +.TP +\fBESRCH\fP +プロセスグループとして 0 が指定されたが、送信プロセスは プロセスグループを持っていない。 +.SH 準拠 +POSIX.1\-2001, POSIX.1\-2008, SVr4, 4.4BSD (\fBkillpg\fP() は 4BSD で初めて登場した). +.SH 注意 +BSD 系システムと System\ V 系システムでは、 許可のチェックに様々な違いがある。 \fBkill\fP(3p) の POSIX の原理 +(rationale) を参照すること。 POSIX で記述されていない違いとしては、返り値 \fBEPERM\fP がある。 BSD +では「送信先プロセスの許可のチェックが 1 つでも失敗した場合は、 シグナルが送信されず、 \fBEPERM\fP が返される」と記述されている。 POSIX +では「送信先プロセスの許可のチェックが全て失敗した場合にのみ、 \fBEPERM\fP が返される」と記述されている。 +.SS "C ライブラリとカーネルの違い" +Linux では、 \fBkillpg\fP() はライブラリ関数として実装されており、 \fIkill(\-pgrp,\ sig)\fP の呼び出しが行われる。 +.SH 関連項目 +\fBgetpgrp\fP(2), \fBkill\fP(2), \fBsignal\fP(2), \fBcredentials\fP(7), +\fBcapabilities\fP(7) +.SH この文書について +この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は +\%https://www.kernel.org/doc/man\-pages/ に書かれている。 diff --git a/manual/LDP_man-pages/draft/man3/profil.3 b/manual/LDP_man-pages/draft/man3/profil.3 index 48e07022..1863c798 100644 --- a/manual/LDP_man-pages/draft/man3/profil.3 +++ b/manual/LDP_man-pages/draft/man3/profil.3 @@ -58,11 +58,11 @@ glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参 \fBprofil\fP(): .nf .\" commit 266865c0e7b79d4196e2cc393693463f03c90bd8 - Since glibc 2.21: + glibc 2.21 以降: _DEFAULT_SOURCE - In glibc 2.19 and 2.20: + glibc 2.19 と 2.20: _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE\ <\ 500) - Up to and including glibc 2.19: + glibc 2.19 以前: _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE\ <\ 500) .fi .SH 説明 @@ -85,13 +85,13 @@ T} Thread safety MT\-Unsafe .TE .sp 1 .SH 準拠 -Similar to a call in SVr4 (but not POSIX.1). +SVr4 のコールに似ている (しかし POSIX.1 ではない)。 .SH バグ \fBprofil\fP() は \fBITIMER_PROF\fP インターバルタイマーも使用しているプログラムでは使用できない (\fBsetitimer\fP(2) 参照)。 .PP .\" Libc 4.4 contained a kernel patch providing a system call profil. -True kernel profiling provides more accurate results. +本当のカーネルプロファイルはより正確な結果を与える。 .SH 関連項目 \fBgprof\fP(1), \fBsprof\fP(1), \fBsetitimer\fP(2), \fBsigaction\fP(2), \fBsignal\fP(2) .SH この文書について diff --git a/manual/LDP_man-pages/draft/man3/psignal.3 b/manual/LDP_man-pages/draft/man3/psignal.3 index 2b4b9a56..1910dd9b 100644 --- a/manual/LDP_man-pages/draft/man3/psignal.3 +++ b/manual/LDP_man-pages/draft/man3/psignal.3 @@ -42,7 +42,7 @@ .\" .TH PSIGNAL 3 2020\-11\-01 GNU "Linux Programmer's Manual" .SH 名前 -psignal, psiginfo \- print signal description +psignal, psiginfo \- シグナルの説明を表示する .SH 書式 .nf \fB#include \fP @@ -56,9 +56,9 @@ glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参 .RE .PP \fBpsignal\fP(): - Since glibc 2.19: + glibc 2.19 以降: _DEFAULT_SOURCE - Glibc 2.19 and earlier: + glibc 2.19 以前: _BSD_SOURCE || _SVID_SOURCE .br \fBpsiginfo\fP(): _POSIX_C_SOURCE\ >=\ 200809L diff --git a/manual/LDP_man-pages/draft/man3/sigpause.3 b/manual/LDP_man-pages/draft/man3/sigpause.3 index aa7abf4a..a1636a8e 100644 --- a/manual/LDP_man-pages/draft/man3/sigpause.3 +++ b/manual/LDP_man-pages/draft/man3/sigpause.3 @@ -74,8 +74,8 @@ T} Thread safety MT\-Safe .\" when the underlying kernel is neither Linux nor a BSD kernel. .\" So, it is safe in Linux kernel. .SH 準拠 -The System V version of \fBsigpause\fP() is standardized in POSIX.1\-2001. It -is also specified in POSIX.1\-2008, where it is marked obsolete. +System V 版の \fBsigpause\fP() は POSIX.1\-2001 で標準化されている。 POSIX.1\-2008 +でも規定されているが、ここでは廃止予定 (obsolete) 扱いとなっている。 .SH 注意 .SS 歴史 .\" __xpg_sigpause: UNIX 95, spec 1170, SVID, SVr4, XPG @@ -88,24 +88,21 @@ Linux では、このルーチンは Sparc (sparc64) アーキテクチャーで .PP .\" Libc4 and libc5 know only about the BSD version. .\" -Glibc uses the BSD version if the \fB_BSD_SOURCE\fP feature test macro is -defined and none of \fB_POSIX_SOURCE\fP, \fB_POSIX_C_SOURCE\fP, \fB_XOPEN_SOURCE\fP, -\fB_GNU_SOURCE\fP, or \fB_SVID_SOURCE\fP is defined. Otherwise, the System V -version is used, and feature test macros must be defined as follows to -obtain the declaration: +機能検査マクロ \fB_BSD_SOURCE\fP が定義され、 \fB_POSIX_SOURCE\fP, \fB_POSIX_C_SOURCE\fP, +\fB_XOPEN_SOURCE\fP, \fB_GNU_SOURCE\fP, \fB_SVID_SOURCE\fP のいずれも定義されていない場合、 glibc は +BSD 版を使う。 それ以外の場合には、System V 版を使用し、この場合には宣言を得るためには以下のように機能検査マクロを定義しなければならない。 .IP * 3 .\" || (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) -Since glibc 2.26: _XOPEN_SOURCE >= 500 +glibc 2.26 以降: _XOPEN_SOURCE >= 500 .IP * -Glibc 2.25 and earlier: _XOPEN_SOURCE +glibc 2.25 以前: _XOPEN_SOURCE .PP .\" .\" For the BSD version, one usually uses a zero .\" .I sigmask .\" to indicate that no signals are to be blocked. -Since glibc 2.19, only the System V version is exposed by -\fI\fP; applications that formerly used the BSD \fBsigpause\fP() -should be amended to use \fBsigsuspend\fP(2). +glibc 2.19 以降では、 \fI\fP では System V 版だけが公開される。 BSD 版の +\fBsigpause\fP() を使用していたアプリケーションは \fBsigsuspend\fP(2) を使用するように修正すべきである。 .SH 関連項目 \fBkill\fP(2), \fBsigaction\fP(2), \fBsigprocmask\fP(2), \fBsigsuspend\fP(2), \fBsigblock\fP(3), \fBsigvec\fP(3), \fBfeature_test_macros\fP(7) diff --git a/manual/LDP_man-pages/draft/man3/sigqueue.3 b/manual/LDP_man-pages/draft/man3/sigqueue.3 index 3ba57ab3..bbec0175 100644 --- a/manual/LDP_man-pages/draft/man3/sigqueue.3 +++ b/manual/LDP_man-pages/draft/man3/sigqueue.3 @@ -89,8 +89,7 @@ union sigval { \fBESRCH\fP \fIpid\fP にマッチする PID のプロセスがない。 .SH バージョン -\fBsigqueue\fP() and the underlying \fBrt_sigqueueinfo\fP() system call first -appeared in Linux 2.2. +\fBsigqueue\fP() とその裏で使われる \fBrt_sigqueueinfo\fP() システムコールは Linux 2.2 で初めて登場した。 .SH 属性 この節で使用されている用語の説明については、 \fBattributes\fP(7) を参照。 .TS @@ -108,13 +107,12 @@ POSIX.1\-2001, POSIX.1\-2008. この関数を呼び出したプロセスにこの関数がシグナルを送ったときに、 シグナルが呼び出し側スレッドにブロックされず、 かつ (シグナルがブロックされなかった、または \fBsigwait\fP(3) を使用するのを待っていることにより) このシグナルを扱うスレッドが何もない場合は、 この関数がリターンする前に、少なくとも そのスレッドに対してシグナルが配送されていなければならない。 -.SS "C library/kernel differences" -On Linux, \fBsigqueue\fP() is implemented using the \fBrt_sigqueueinfo\fP(2) -system call. The system call differs in its third argument, which is the -\fIsiginfo_t\fP structure that will be supplied to the receiving process's -signal handler or returned by the receiving process's \fBsigtimedwait\fP(2) -call. Inside the glibc \fBsigqueue\fP() wrapper, this argument, \fIuinfo\fP, is -initialized as follows: +.SS "C ライブラリとカーネルの違い" +Linux では、 \fBsigqueue\fP() は \fBrt_sigqueueinfo\fP(2) システムコールを使って実装されている。 両者には 3 +番目の引き数に違いがあり、 \fBrt_sigqueueinfo\fP(2) では 3 番目の引き数は \fIsiginfo_t\fP 構造体である。 +\fIsiginfo_t\fP 構造体は、シグナルを受信するプロセスのシグナルハンドラーに渡されたり、 シグナル受信プロセスの +\fBsigtimedwait\fP(2) システムコールから返されたりする。 glibc の \fBsigqueue\fP() ラッパー関数内部では、 +この引き数 \fIuinfo\fP は以下のように初期化される。 .PP .in +4n .EX diff --git a/manual/LDP_man-pages/draft/man3/sigset.3 b/manual/LDP_man-pages/draft/man3/sigset.3 index 6aa66953..bb9a1226 100644 --- a/manual/LDP_man-pages/draft/man3/sigset.3 +++ b/manual/LDP_man-pages/draft/man3/sigset.3 @@ -117,11 +117,10 @@ T{ T} Thread safety MT\-Safe .TE .SH 準拠 -SVr4, POSIX.1\-2001, POSIX.1\-2008. These functions are obsolete: do not use -them in new programs. POSIX.1\-2008 marks \fBsighold\fP(), \fBsigignore\fP(), -\fBsigpause\fP(3), \fBsigrelse\fP(), and \fBsigset\fP() as obsolete, recommending -the use of \fBsigaction\fP(2), \fBsigprocmask\fP(2), \fBpthread_sigmask\fP(3), and -\fBsigsuspend\fP(2) instead. +SVr4, POSIX.1\-2001, POSIX.1\-2008. これらの関数は廃止予定である。新しいプログラムでは使用しないこと。 +POSIX.1\-2008 は、 \fBsighold\fP(), \fBsigignore\fP(), \fBsigpause\fP(3), \fBsigrelse\fP(), +\fBsigset\fP() を廃止予定としている。 代わりに、 \fBsigaction\fP(2), \fBsigprocmask\fP(2), +\fBpthread_sigmask\fP(3), \fBsigsuspend\fP(2) の使用が推奨されている。 .SH 注意 これらの関数は glibc 2.1 で登場した。 .PP diff --git a/manual/LDP_man-pages/draft/man3/sigsetops.3 b/manual/LDP_man-pages/draft/man3/sigsetops.3 new file mode 100644 index 00000000..60bd8c18 --- /dev/null +++ b/manual/LDP_man-pages/draft/man3/sigsetops.3 @@ -0,0 +1,149 @@ +.\" Copyright (c) 1994 Mike Battersby +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. The author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\" Modified by aeb, 960721 +.\" 2005-11-21, mtk, added descriptions of sigisemptyset(), sigandset(), +.\" and sigorset() +.\" 2007-10-26 mdw added wording that a sigset_t must be initialized +.\" prior to use +.\" +.\"******************************************************************* +.\" +.\" This file was generated with po4a. Translate the source file. +.\" +.\"******************************************************************* +.\" +.\" Japanese Version Copyright (c) 1998 HANATAKA Shinya +.\" all rights reserved. +.\" Translated 1998-05-24, HANATAKA Shinya +.\" Updated 2005-12-05, Akihiro MOTOKI, Catch up to LDP man-pages 2.16 +.\" Updated 2008-02-09, Akihiro MOTOKI , LDP v2.77 +.\" +.TH SIGSETOPS 3 2020\-12\-21 Linux "Linux Programmer's Manual" +.SH 名前 +sigemptyset, sigfillset, sigaddset, sigdelset, sigismember \- POSIX シグナル集合の操作 +.SH 書式 +\fB#include \fP +.PP +\fBint sigemptyset(sigset_t *\fP\fIset\fP\fB);\fP +.PP +\fBint sigfillset(sigset_t *\fP\fIset\fP\fB);\fP +.PP +\fBint sigaddset(sigset_t *\fP\fIset\fP\fB, int \fP\fIsignum\fP\fB);\fP +.PP +\fBint sigdelset(sigset_t *\fP\fIset\fP\fB, int \fP\fIsignum\fP\fB);\fP +.PP +\fBint sigismember(const sigset_t *\fP\fIset\fP\fB, int \fP\fIsignum\fP\fB);\fP +.PP +.RS -4 +glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): +.RE +.PP +.ad l +\fBsigemptyset\fP(), \fBsigfillset\fP(), \fBsigaddset\fP(), \fBsigdelset\fP(), +\fBsigismember\fP(): +.RS 4 +_POSIX_C_SOURCE +.RE +.ad b +.SH 説明 +これらの関数は POSIX シグナル集合(signal set)を操作するため使用する。 +.PP +\fBsigemptyset\fP() は \fIset\fP で与えられたシグナル集合を空に初期化し、シグナルが一つも 含まれていない状態にする。 +.PP +\fBsigfillset\fP() は \fIset\fP で与えられたシグナル集合が全てのシグナルを含むようにする。 +.PP +\fBsigaddset\fP() と \fBsigdelset\fP() は \fIset\fP に \fIsignum\fP +シグナルをそれぞれ加えたり、削除したりする。 +.PP +\fBsigismember\fP() は \fIsignum\fP が \fIset\fP に含まれているかどうかをテストする。 +.PP +\fIsigset_t\fP 型のオブジェクトは、関数 \fBsigaddset\fP(), \fBsigdelset\fP(), \fBsigismember\fP() +や後述の glibc の追加関数 (\fBsigisemptyset\fP(), \fBsigandset\fP(), \fBsigorset\fP()) に渡す前に、 +\fBsigemptyset\fP() か \fBsigfillset\fP() を呼び出して初期化しなければならない。 +初期化しなかった場合の結果は未定義である。 +.SH 返り値 +\fBsigemptyset\fP(), \fBsigfillset\fP(), \fBsigaddset\fP(), \fBsigdelset\fP() は成功すれば 0 +を、エラーの場合は \-1 を返す。 +.PP +\fBsigismember\fP() は \fIsignum\fP が \fIset\fP のメンバの場合 1 を返し、メンバでない場合 0 を返す。 +エラーの場合、\-1 を返す。 +.PP +エラーの場合、 \fIerrno\fP にエラーの原因を示す値を設定する。 +.SH エラー +.TP +\fBEINVAL\fP +\fIsignum\fP が有効なシグナルではない。 +.SH 属性 +この節で使用されている用語の説明については、 \fBattributes\fP(7) を参照。 +.TS +allbox; +lbw31 lb lb +l l l. +インターフェース 属性 値 +T{ +\fBsigemptyset\fP(), +\fBsigfillset\fP(), +.br +\fBsigaddset\fP(), +\fBsigdelset\fP(), +.br +\fBsigismember\fP(), +\fBsigisemptyset\fP(), +.br +\fBsigorset\fP(), +\fBsigandset\fP() +T} Thread safety MT\-Safe +.TE +.SH 準拠 +POSIX.1\-2001, POSIX.1\-2008. +.SH 注意 +.\" +When creating a filled signal set, the glibc \fBsigfillset\fP() function does +not include the two real\-time signals used internally by the NPTL threading +implementation. See \fBnptl\fP(7) for details. +.SS "glibc での拡張" +\fB_GNU_SOURCE\fP 機能検査マクロが定義されていると、 \fI\fP でシグナル集合を操作する 3 +つの関数が追加で公開される。 +.PP +.nf +\fBint sigisemptyset(const sigset_t *\fP\fIset\fP\fB);\fP +\fBint sigorset(sigset_t *\fP\fIdest\fP\fB, const sigset_t *\fP\fIleft\fP\fB,\fP +\fB const sigset_t *\fP\fIright\fP\fB);\fP +\fBint sigandset(sigset_t *\fP\fIdest\fP\fB, const sigset_t *\fP\fIleft\fP\fB,\fP +\fB const sigset_t *\fP\fIright\fP\fB);\fP +.fi +.PP +\fBsigisemptyset\fP() は \fIset\fP にシグナルが一つも含まれていなければ 1 を返し、 それ以外は 0 を返す。 +.PP +\fBsigorset\fP() は集合 \fIleft\fP と \fIright\fP の和集合を \fIdest\fP に設定する。 \fBsigandset\fP() は集合 +\fIleft\fP と \fIright\fP の積集合を \fIdest\fP に設定する。 どちらの関数も成功すると 0 を返し、失敗時には \-1 を返す。 +.PP +これらの関数は非標準であり、(他にも同様の関数を提供しているシステムも いくつかはあるが) 移植性を考慮したアプリケーションでは使用を避けるべき +である。 +.SH 関連項目 +\fBsigaction\fP(2), \fBsigpending\fP(2), \fBsigprocmask\fP(2), \fBsigsuspend\fP(2) +.SH この文書について +この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は +\%https://www.kernel.org/doc/man\-pages/ に書かれている。 diff --git a/manual/LDP_man-pages/draft/man3/sigvec.3 b/manual/LDP_man-pages/draft/man3/sigvec.3 index 2ecd603a..9736184f 100644 --- a/manual/LDP_man-pages/draft/man3/sigvec.3 +++ b/manual/LDP_man-pages/draft/man3/sigvec.3 @@ -94,10 +94,8 @@ struct sigvec { フィールドはハンドラーが呼ばれた際の挙動を制御するフラグを指定する。 このフィールドには、0 か、以下のフラグを 1個以上指定できる: .TP \fBSV_INTERRUPT\fP -If the signal handler interrupts a blocking system call, then upon return -from the handler the system call s not be restarted: instead it fails with -the error \fBEINTR\fP. If this flag is not specified, then system calls are -restarted by default. +シグナルハンドラーが停止中のシステムコールを中断した場合、 ハンドラーから復帰しても、システムコールは再開されず、 エラー \fBEINTR\fP +で失敗する。 このフラグを指定しなかった場合、システムコールは デフォルトで再開される。 .TP \fBSV_RESETHAND\fP シグナルハンドラーを呼び出す前にシグナルの動作を デフォルトにリセットする。 このフラグを指定しなかった場合、もう一度 \fBsigvec\fP() @@ -157,10 +155,9 @@ T} Thread safety MT\-Safe これらの関数のうち \fBsiggetmask\fP() 以外の全ては 4.3BSD にあった。 \fBsiggetmask\fP() の出自ははっきりしない。 これらの関数は廃止予定であり、新しいプログラムでは使用しないこと。 .SH 注意 -On 4.3BSD, the \fBsignal\fP() function provided reliable semantics (as when -calling \fBsigvec\fP() with \fIvec.sv_mask\fP equal to 0). On System V, -\fBsignal\fP() provides unreliable semantics. POSIX.1 leaves these aspects of -\fBsignal\fP() unspecified. See \fBsignal\fP(2) for further details. +4.3BSD では、信頼性のあるシグナル処理機構を提供する (\fIvec.sv_mask\fP を 0 で \fBsigvec\fP() +を呼び出したときと同様)。 System V が提供する処理機構は信頼性のないものである。 POSIX.1 では、 \fBsignal\fP() +のこの点は規定しないままとなっている。 さらなる詳細については \fBsignal\fP(2) を参照。 .PP BSD と System V のどちらのシステムでも シグナルを待つために、 \fBsigpause\fP(3) という名前の関数が提供されているが、 この関数の引き数は両方のシステムで異なる。 詳細は \fBsigpause\fP(3) を参照。 diff --git a/manual/LDP_man-pages/draft/man3/sigwait.3 b/manual/LDP_man-pages/draft/man3/sigwait.3 index 60af1df6..1fc20815 100644 --- a/manual/LDP_man-pages/draft/man3/sigwait.3 +++ b/manual/LDP_man-pages/draft/man3/sigwait.3 @@ -50,10 +50,10 @@ glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参 .ad l \fBsigwait\fP(): .RS 4 -Since glibc 2.26: +glibc 2.26 以降: _POSIX_C_SOURCE >= 199506L .br -Glibc 2.25 and earlier: +Glibc 2.25 以前: _POSIX_C_SOURCE .RE .ad b @@ -93,7 +93,7 @@ POSIX.1\-2001, POSIX.1\-2008. The glibc implementation of \fBsigwait\fP() silently ignores attempts to wait for the two real\-time signals that are used internally by the NPTL threading implementation. See \fBnptl\fP(7) for details. -.SH EXAMPLES +.SH 例 \fBpthread_sigmask\fP(3) を参照。 .SH 関連項目 \fBsigaction\fP(2), \fBsignalfd\fP(2), \fBsigpending\fP(2), \fBsigsuspend\fP(2), diff --git a/manual/LDP_man-pages/draft/man7/signal-safety.7 b/manual/LDP_man-pages/draft/man7/signal-safety.7 new file mode 100644 index 00000000..cc219a2e --- /dev/null +++ b/manual/LDP_man-pages/draft/man7/signal-safety.7 @@ -0,0 +1,321 @@ +.\" Copyright (c) 2016 Michael Kerrisk +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. The author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\"******************************************************************* +.\" +.\" This file was generated with po4a. Translate the source file. +.\" +.\"******************************************************************* +.TH SIGNAL\-SAFETY 7 2020\-12\-21 Linux "Linux Programmer's Manual" +.SH 名前 +signal\-safety \- 非同期シグナルで安全な関数 (async\-signal\-safe functions) +.SH 説明 +An \fIasync\-signal\-safe\fP function is one that can be safely called from +within a signal handler. Many functions are \fInot\fP async\-signal\-safe. In +particular, nonreentrant functions are generally unsafe to call from a +signal handler. +.PP +The kinds of issues that render a function unsafe can be quickly understood +when one considers the implementation of the \fIstdio\fP library, all of whose +functions are not async\-signal\-safe. +.PP +When performing buffered I/O on a file, the \fIstdio\fP functions must maintain +a statically allocated data buffer along with associated counters and +indexes (or pointers) that record the amount of data and the current +position in the buffer. Suppose that the main program is in the middle of a +call to a \fIstdio\fP function such as \fBprintf\fP(3) where the buffer and +associated variables have been partially updated. If, at that moment, the +program is interrupted by a signal handler that also calls \fBprintf\fP(3), +then the second call to \fBprintf\fP(3) will operate on inconsistent data, +with unpredictable results. +.PP +To avoid problems with unsafe functions, there are two possible choices: +.IP 1. 3 +Ensure that (a) the signal handler calls only async\-signal\-safe functions, +and (b) the signal handler itself is reentrant with respect to global +variables in the main program. +.IP 2. +Block signal delivery in the main program when calling functions that are +unsafe or operating on global data that is also accessed by the signal +handler. +.PP +Generally, the second choice is difficult in programs of any complexity, so +the first choice is taken. +.PP +POSIX.1 specifies a set of functions that an implementation must make +async\-signal\-safe. (An implementation may provide safe implementations of +additional functions, but this is not required by the standard and other +implementations may not provide the same guarantees.) +.PP +In general, a function is async\-signal\-safe either because it is reentrant +or because it is atomic with respect to signals (i.e., its execution can't +be interrupted by a signal handler). +.PP +The set of functions required to be async\-signal\-safe by POSIX.1 is shown in +the following table. The functions not otherwise noted were required to be +async\-signal\-safe in POSIX.1\-2001; the table details changes in the +subsequent standards. +.PP +.TS +lb lb +l l. +関数 Notes +\fBabort\fP(3) POSIX.1\-2001 TC1 で追加 +\fBaccept\fP(2) +\fBaccess\fP(2) +\fBaio_error\fP(3) +\fBaio_return\fP(3) +\fBaio_suspend\fP(3) 下記の「注意」を参照 +\fBalarm\fP(2) +\fBbind\fP(2) +\fBcfgetispeed\fP(3) +\fBcfgetospeed\fP(3) +\fBcfsetispeed\fP(3) +\fBcfsetospeed\fP(3) +\fBchdir\fP(2) +\fBchmod\fP(2) +\fBchown\fP(2) +\fBclock_gettime\fP(2) +\fBclose\fP(2) +\fBconnect\fP(2) +\fBcreat\fP(2) +\fBdup\fP(2) +\fBdup2\fP(2) +\fBexecl\fP(3) POSIX.1\-2008 で追加; 下記の「注意」を参照 +\fBexecle\fP(3) 下記の「注意」を参照 +\fBexecv\fP(3) POSIX.1\-2008 で追加 +\fBexecve\fP(2) +\fB_exit\fP(2) +\fB_Exit\fP(2) +\fBfaccessat\fP(2) POSIX.1\-2008 で追加 +\fBfchdir\fP(2) POSIX.1\-2008 TC1 で追加 +\fBfchmod\fP(2) +\fBfchmodat\fP(2) POSIX.1\-2008 で追加 +\fBfchown\fP(2) +\fBfchownat\fP(2) POSIX.1\-2008 で追加 +\fBfcntl\fP(2) +\fBfdatasync\fP(2) +\fBfexecve\fP(3) POSIX.1\-2008 で追加 +\fBffs\fP(3) POSIX.1\-2008 TC2 で追加 +\fBfork\fP(2) 下記の「注意」を参照 +\fBfstat\fP(2) +\fBfstatat\fP(2) POSIX.1\-2008 で追加 +\fBfsync\fP(2) +\fBftruncate\fP(2) +\fBfutimens\fP(3) POSIX.1\-2008 で追加 +\fBgetegid\fP(2) +\fBgeteuid\fP(2) +\fBgetgid\fP(2) +\fBgetgroups\fP(2) +\fBgetpeername\fP(2) +\fBgetpgrp\fP(2) +\fBgetpid\fP(2) +\fBgetppid\fP(2) +\fBgetsockname\fP(2) +\fBgetsockopt\fP(2) +\fBgetuid\fP(2) +\fBhtonl\fP(3) POSIX.1\-2008 TC2 で追加 +\fBhtons\fP(3) POSIX.1\-2008 TC2 で追加 +\fBkill\fP(2) +\fBlink\fP(2) +\fBlinkat\fP(2) POSIX.1\-2008 で追加 +\fBlisten\fP(2) +\fBlongjmp\fP(3) POSIX.1\-2008 TC2 で追加; 下記の「注意」を参照 +\fBlseek\fP(2) +\fBlstat\fP(2) +\fBmemccpy\fP(3) POSIX.1\-2008 TC2 で追加 +\fBmemchr\fP(3) POSIX.1\-2008 TC2 で追加 +\fBmemcmp\fP(3) POSIX.1\-2008 TC2 で追加 +\fBmemcpy\fP(3) POSIX.1\-2008 TC2 で追加 +\fBmemmove\fP(3) POSIX.1\-2008 TC2 で追加 +\fBmemset\fP(3) POSIX.1\-2008 TC2 で追加 +\fBmkdir\fP(2) +\fBmkdirat\fP(2) POSIX.1\-2008 で追加 +\fBmkfifo\fP(3) +\fBmkfifoat\fP(3) POSIX.1\-2008 で追加 +\fBmknod\fP(2) POSIX.1\-2008 で追加 +\fBmknodat\fP(2) POSIX.1\-2008 で追加 +\fBntohl\fP(3) POSIX.1\-2008 TC2 で追加 +\fBntohs\fP(3) POSIX.1\-2008 TC2 で追加 +\fBopen\fP(2) +\fBopenat\fP(2) POSIX.1\-2008 で追加 +\fBpause\fP(2) +\fBpipe\fP(2) +\fBpoll\fP(2) +\fBposix_trace_event\fP(3) +\fBpselect\fP(2) +\fBpthread_kill\fP(3) POSIX.1\-2008 TC1 で追加 +\fBpthread_self\fP(3) POSIX.1\-2008 TC1 で追加 +\fBpthread_sigmask\fP(3) POSIX.1\-2008 TC1 で追加 +\fBraise\fP(3) +\fBread\fP(2) +\fBreadlink\fP(2) +\fBreadlinkat\fP(2) POSIX.1\-2008 で追加 +\fBrecv\fP(2) +\fBrecvfrom\fP(2) +\fBrecvmsg\fP(2) +\fBrename\fP(2) +\fBrenameat\fP(2) POSIX.1\-2008 で追加 +\fBrmdir\fP(2) +\fBselect\fP(2) +\fBsem_post\fP(3) +\fBsend\fP(2) +\fBsendmsg\fP(2) +\fBsendto\fP(2) +\fBsetgid\fP(2) +\fBsetpgid\fP(2) +\fBsetsid\fP(2) +\fBsetsockopt\fP(2) +\fBsetuid\fP(2) +\fBshutdown\fP(2) +\fBsigaction\fP(2) +\fBsigaddset\fP(3) +\fBsigdelset\fP(3) +\fBsigemptyset\fP(3) +\fBsigfillset\fP(3) +\fBsigismember\fP(3) +\fBsiglongjmp\fP(3) POSIX.1\-2008 TC2 で追加; 下記の「注意」を参照 +\fBsignal\fP(2) +\fBsigpause\fP(3) +\fBsigpending\fP(2) +\fBsigprocmask\fP(2) +\fBsigqueue\fP(2) +\fBsigset\fP(3) +\fBsigsuspend\fP(2) +\fBsleep\fP(3) +\fBsockatmark\fP(3) POSIX.1\-2001 TC2 で追加 +\fBsocket\fP(2) +\fBsocketpair\fP(2) +\fBstat\fP(2) +\fBstpcpy\fP(3) POSIX.1\-2008 TC2 で追加 +\fBstpncpy\fP(3) POSIX.1\-2008 TC2 で追加 +\fBstrcat\fP(3) POSIX.1\-2008 TC2 で追加 +\fBstrchr\fP(3) POSIX.1\-2008 TC2 で追加 +\fBstrcmp\fP(3) POSIX.1\-2008 TC2 で追加 +\fBstrcpy\fP(3) POSIX.1\-2008 TC2 で追加 +\fBstrcspn\fP(3) POSIX.1\-2008 TC2 で追加 +\fBstrlen\fP(3) POSIX.1\-2008 TC2 で追加 +\fBstrncat\fP(3) POSIX.1\-2008 TC2 で追加 +\fBstrncmp\fP(3) POSIX.1\-2008 TC2 で追加 +\fBstrncpy\fP(3) POSIX.1\-2008 TC2 で追加 +\fBstrnlen\fP(3) POSIX.1\-2008 TC2 で追加 +\fBstrpbrk\fP(3) POSIX.1\-2008 TC2 で追加 +\fBstrrchr\fP(3) POSIX.1\-2008 TC2 で追加 +\fBstrspn\fP(3) POSIX.1\-2008 TC2 で追加 +\fBstrstr\fP(3) POSIX.1\-2008 TC2 で追加 +\fBstrtok_r\fP(3) POSIX.1\-2008 TC2 で追加 +\fBsymlink\fP(2) +\fBsymlinkat\fP(2) POSIX.1\-2008 で追加 +\fBtcdrain\fP(3) +\fBtcflow\fP(3) +\fBtcflush\fP(3) +\fBtcgetattr\fP(3) +\fBtcgetpgrp\fP(3) +\fBtcsendbreak\fP(3) +\fBtcsetattr\fP(3) +\fBtcsetpgrp\fP(3) +\fBtime\fP(2) +\fBtimer_getoverrun\fP(2) +\fBtimer_gettime\fP(2) +\fBtimer_settime\fP(2) +\fBtimes\fP(2) +\fBumask\fP(2) +\fBuname\fP(2) +\fBunlink\fP(2) +\fBunlinkat\fP(2) POSIX.1\-2008 で追加 +\fButime\fP(2) +\fButimensat\fP(2) POSIX.1\-2008 で追加 +\fButimes\fP(2) POSIX.1\-2008 で追加 +\fBwait\fP(2) +\fBwaitpid\fP(2) +\fBwcpcpy\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwcpncpy\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwcscat\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwcschr\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwcscmp\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwcscpy\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwcscspn\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwcslen\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwcsncat\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwcsncmp\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwcsncpy\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwcsnlen\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwcspbrk\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwcsrchr\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwcsspn\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwcsstr\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwcstok\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwmemchr\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwmemcmp\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwmemcpy\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwmemmove\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwmemset\fP(3) POSIX.1\-2008 TC2 で追加 +\fBwrite\fP(2) +.TE +.PP +注意: +.IP * 3 +POSIX.1\-2001 and POSIX.1\-2001 TC2 required the functions \fBfpathconf\fP(3), +\fBpathconf\fP(3), and \fBsysconf\fP(3) to be async\-signal\-safe, but this +requirement was removed in POSIX.1\-2008. +.IP * +If a signal handler interrupts the execution of an unsafe function, and the +handler terminates via a call to \fBlongjmp\fP(3) or \fBsiglongjmp\fP(3) and the +program subsequently calls an unsafe function, then the behavior of the +program is undefined. +.IP * +.\" http://www.opengroup.org/austin/aardvark/latest/xshbug3.txt +.\" +POSIX.1\-2001 TC1 clarified that if an application calls \fBfork\fP(2) from a +signal handler and any of the fork handlers registered by +\fBpthread_atfork\fP(3) calls a function that is not async\-signal\-safe, the +behavior is undefined. A future revision of the standard is likely to +remove \fBfork\fP(2) from the list of async\-signal\-safe functions. +.IP * 3 +.\" +Asynchronous signal handlers that call functions which are cancellation +points and nest over regions of deferred cancellation may trigger +cancellation whose behavior is as if asynchronous cancellation had occurred +and may cause application state to become inconsistent. +.SS errno +.\" +Fetching and setting the value of \fIerrno\fP is async\-signal\-safe provided +that the signal handler saves \fIerrno\fP on entry and restores its value +before returning. +.SS "Deviations in the GNU C library" +The following known deviations from the standard occur in the GNU C library: +.IP * 3 +.\" https://sourceware.org/bugzilla/show_bug.cgi?id=19534 +Before glibc 2.24, \fBexecl\fP(3) and \fBexecle\fP(3) employed \fBrealloc\fP(3) +internally and were consequently not async\-signal\-safe. This was fixed in +glibc 2.24. +.IP * +.\" FIXME . https://sourceware.org/bugzilla/show_bug.cgi?id=13172 +The glibc implementation of \fBaio_suspend\fP(3) is not async\-signal\-safe +because it uses \fBpthread_mutex_lock\fP(3) internally. +.SH 関連項目 +\fBsigaction\fP(2), \fBsignal\fP(7), \fBstandards\fP(7) +.SH この文書について +この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は +\%https://www.kernel.org/doc/man\-pages/ に書かれている。 diff --git a/manual/LDP_man-pages/draft/man7/signal.7 b/manual/LDP_man-pages/draft/man7/signal.7 new file mode 100644 index 00000000..b4d03fbe --- /dev/null +++ b/manual/LDP_man-pages/draft/man7/signal.7 @@ -0,0 +1,662 @@ +.\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de) +.\" and Copyright (c) 2002, 2006, 2020 by Michael Kerrisk +.\" and Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk +.\" +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. The author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\" Modified Sat Jul 24 17:34:08 1993 by Rik Faith (faith@cs.unc.edu) +.\" Modified Sun Jan 7 01:41:27 1996 by Andries Brouwer (aeb@cwi.nl) +.\" Modified Sun Apr 14 12:02:29 1996 by Andries Brouwer (aeb@cwi.nl) +.\" Modified Sat Nov 13 16:28:23 1999 by Andries Brouwer (aeb@cwi.nl) +.\" Modified 10 Apr 2002, by Michael Kerrisk +.\" Modified 7 Jun 2002, by Michael Kerrisk +.\" Added information on real-time signals +.\" Modified 13 Jun 2002, by Michael Kerrisk +.\" Noted that SIGSTKFLT is in fact unused +.\" 2004-12-03, Modified mtk, added notes on RLIMIT_SIGPENDING +.\" 2006-04-24, mtk, Added text on changing signal dispositions, +.\" signal mask, and pending signals. +.\" 2008-07-04, mtk: +.\" Added section on system call restarting (SA_RESTART) +.\" Added section on stop/cont signals interrupting syscalls. +.\" 2008-10-05, mtk: various additions +.\" +.\"******************************************************************* +.\" +.\" This file was generated with po4a. Translate the source file. +.\" +.\"******************************************************************* +.\" +.\" Japanese Version Copyright (c) 1997 Takafumi Naka +.\" and 2005-2008 Akihiro MOTOKI +.\" all rights reserved. +.\" Translated 1997-02-13, Takafumi Naka +.\" Modified 1999-06-22, Tatsuo SEKINE +.\" Modified 1999-07-18, Takafumi Naka +.\" Modified 1999-12-06, NAKANO Takeo , LDP v1.28 +.\" Updated 2003-07-24, Kentaro Shirakata +.\" Updated 2005-02-23, Akihiro MOTOKI +.\" Updated 2006-07-28, Akihiro MOTOKI , LDP v2.36 +.\" Updated 2007-05-28, Akihiro MOTOKI , LDP v2.50 +.\" Updated 2007-09-08, Akihiro MOTOKI , LDP v2.64 +.\" Updated 2008-08-11, Akihiro MOTOKI , LDP v3.05 +.\" Updated 2008-11-21, Akihiro MOTOKI , LDP v3.13 +.\" Updated 2010-04-10, Akihiro MOTOKI , LDP v3.24 +.\" Updated 2012-05-29, Akihiro MOTOKI +.\" Updated 2013-03-26, Akihiro MOTOKI +.\" +.TH SIGNAL 7 2020\-12\-21 Linux "Linux Programmer's Manual" +.SH 名前 +signal \- シグナルの概要 +.SH 説明 +Linux は POSIX 信頼シグナル (reliable signal; 以後 "標準シグナル"と表記) と POSIX +リアルタイムシグナルの両方に対応している。 +.SS シグナル処理方法 +シグナルはそれぞれ現在の「処理方法 (disposition)」を保持しており、 この処理方法によりシグナルが配送された際にプロセスが +どのような振舞いをするかが決まる。 +.PP +後述の表の "動作" の欄のエントリーは各シグナルのデフォルトの 処理方法を示しており、以下のような意味を持つ。 +.IP Term +デフォルトの動作はプロセス終了。 +.IP Ign +デフォルトの動作はこのシグナルの無視。 +.IP Core +デフォルトの動作はプロセス終了とコアダンプ出力 (\fBcore\fP(5) 参照)。 +.IP Stop +デフォルトの動作はプロセスの一時停止。 +.IP Cont +デフォルトの動作は、プロセスが停止中の場合にその実行の再開。 +.PP +プロセスは、 \fBsigaction\fP(2) や \fBsignal\fP(2) を使って、シグナルの処理方法を変更することができる +(\fBsignal\fP(2) の方がシグナルハンドラーを設定する際の移植性が低い; 詳細は \fBsignal\fP(2) を参照)。 +シグナルの配送時に起こる動作として プロセスが選択できるのは、次のいずれか一つである。 デフォルトの動作を実行する、シグナルを無視する、 +\fIシグナルハンドラー (signal handler)\fP でシグナルを捕捉する。シグナルハンドラーとは、シグナル配送時に +自動的に起動されるプログラマ定義の関数である。 +.PP +デフォルトでは、シグナルハンドラーは通常のプロセスのスタック上で起動される。 シグナルハンドラーが代替スタック (alternate stack) +を使用するように設定する こともできる。代替スタックを使用するように設定する方法と、どのような際に 代替スタックが役に立つかについての議論については +\fBsigaltstack\fP(2) を参照のこと。 +.PP +シグナルの処理方法はプロセス単位の属性である。 マルチスレッドのアプリケーションでは、あるシグナルの処理方法は 全てのスレッドで同じである。 +.PP +\fBfork\fP(2) 経由で作成された子プロセスは、親プロセスのシグナルの処理方法の コピーを継承する。 \fBexecve\fP(2) +の前後で、ハンドラーが設定されているシグナルの処理方法はデフォルトにリセットされ、 無視が設定されているシグナルの処理方法は変更されずそのままとなる。 +.SS シグナルの送信 +以下のシステムコールとライブラリ関数を使って、 呼び出し者はシグナルを送信することができる。 +.TP +\fBraise\fP(3) +呼び出したスレッドにシグナルを送る。 +.TP +\fBkill\fP(2) +指定されたプロセスや、指定されたプロセスグループの全メンバー、 システムの全プロセスにシグナルを送る。 +.TP +\fBpidfd_send_signal\fP(2) +Sends a signal to a process identified by a PID file descriptor. +.TP +\fBkillpg\fP(3) +指定されたプロセスグループの全メンバーにシグナルを送る。 +.TP +\fBpthread_kill\fP(3) +呼び出し者と同じプロセス内の指定された POSIX スレッドにシグナルを送る。 +.TP +\fBtgkill\fP(2) +指定されたプロセス内の指定されたスレッドにシグナルを送る (このシステムコールを使って \fBpthread_kill\fP(3) は実装されている)。 +.TP +\fBsigqueue\fP(3) +指定されたプロセスに付属データとともにリアルタイムシグナルを送る。 +.SS シグナルが捕捉されるのを待つ +以下のシステムコールを使って、シグナルが捕捉されるまで 呼び出したスレッドの実行を中断 (suspend) することができる +(ハンドラーが設定されていないシグナルによりそのプロセスが終了した 場合にも実行の停止は終了する)。 +.TP +\fBpause\fP(2) +何かシグナルが捕捉されるまで実行を停止する。 +.TP +\fBsigsuspend\fP(2) +.\" +一時的にシグナルマスク (下記参照) を変更し、 マスクされていないシグナルのいずれかが捕捉されるまで 実行を中断する。 +.SS シグナルの同期受信 +シグナルハンドラー経由でシグナルを非同期 (asynchronously) で捕捉する以外にも、 シグナルを同期 (synchronously) +して受け付けることもできる。 同期して受け付けるとは、シグナルが配送されるまで実行を停止 (block) +するということである。シグナルを受け付けた際に、カーネルは そのシグナルに関する情報を呼び出し者に返す。 これを行う一般的な方法が二つある。 +.IP * 2 +\fBsigwaitinfo\fP(2), \fBsigtimedwait\fP(2), \fBsigwait\fP(3) +は、指定されたシグナル集合のシグナルの一つが配送されるまで実行を中断する。 どのシステムコールや関数でも、配送されたシグナルに関する情報が返される。 +.IP * +\fBsignalfd\fP(2) が返すファイルディスクリプターを使うと、呼び出し元に配送された シグナルに関する情報を読み出すことができる。 +このファイルディスクリプターからの \fBread\fP(2) は、 \fBsignalfd\fP(2) +の呼び出し時に指定されたシグナル集合のシグナルの一つが呼び出し元に 配送されるまで停止 (block) する。 \fBread\fP(2) +が返すバッファーにはシグナルに関する情報を格納した構造体が入っている。 +.SS シグナルマスクと処理待ちシグナル +シグナルは \fIブロック (block)\fP されることがある。ブロックされると、そのシグナルは その後ブロックを解除されるまで配送されなくなる。 +シグナルが生成されてから配送されるまでの間、そのシグナルは \fI処理待ち (pending)\fP であると呼ばれる。 +.PP +プロセス内の各スレッドは、それぞれ独立な \fIシグナルマスク (signal mask)\fP を持つ。シグナルマスクはそのスレッドが現在ブロックしている +シグナル集合を示すものである。 スレッドは、 \fBpthread_sigmask\fP(3) を使って自分のシグナルマスクを操作できる。 +伝統的なシングルスレッドのアプリケーションでは、 \fBsigprocmask\fP(2) を使って、シグナルマスクを操作できる。 +.PP +\fBfork\fP(2) 経由で作成された子プロセスは親プロセスのシグナルマスクのコピーを継承する。 \fBexecve\fP(2) +の前後でシグナルマスクは保持される。 +.PP +A signal may be process\-directed or thread\-directed. A process\-directed +signal is one that is targeted at (and thus pending for) the process as a +whole. A signal may be process\-directed because it was generated by the +kernel for reasons other than a hardware exception, or because it was sent +using \fBkill\fP(2) or \fBsigqueue\fP(3). A thread\-directed signal is one that +is targeted at a specific thread. A signal may be thread\-directed because +it was generated as a consequence of executing a specific machine\-language +instruction that triggered a hardware exception (e.g., \fBSIGSEGV\fP for an +invalid memory access, or \fBSIGFPE\fP for a math error), or because it was +targeted at a specific thread using interfaces such as \fBtgkill\fP(2) or +\fBpthread_kill\fP(3). +.PP +.\" Joseph C. Sible notes: +.\" On Linux, if the main thread has the signal unblocked, then the kernel +.\" will always deliver the signal there, citing this kernel code +.\" +.\" Per this comment in kernel/signal.c since time immemorial: +.\" +.\" /* +.\" * Now find a thread we can wake up to take the signal off the queue. +.\" * +.\" * If the main thread wants the signal, it gets first crack. +.\" * Probably the least surprising to the average bear. +.\" */ +.\" +.\" But this does not mean the signal will be delivered only in the +.\" main thread, since if a handler is already executing in the main thread +.\" (and thus the signal is blocked in that thread), then a further +.\" might be delivered in a different thread. +.\" +A process\-directed signal may be delivered to any one of the threads that +does not currently have the signal blocked. If more than one of the threads +has the signal unblocked, then the kernel chooses an arbitrary thread to +which to deliver the signal. +.PP +スレッドは、 \fBsigpending\fP(2) を使って、現在処理待ちのシグナル集合を取得することができる。 +この集合は、プロセス宛ての処理待ちシグナルと 呼び出したスレッド宛てのシグナルの両方から構成される。 +.PP +.\" +\fBfork\fP(2) 経由で作成された子プロセスでは、処理待ちのシグナル集合は空の集合で初期化される。 \fBexecve\fP(2) +の前後で、処理待ちのシグナル集合は保持される。 +.SS "Execution of signal handlers" +Whenever there is a transition from kernel\-mode to user\-mode execution +(e.g., on return from a system call or scheduling of a thread onto the CPU), +the kernel checks whether there is a pending unblocked signal for which the +process has established a signal handler. If there is such a pending +signal, the following steps occur: +.IP 1. 3 +The kernel performs the necessary preparatory steps for execution of the +signal handler: +.RS +.IP a) 3 +The signal is removed from the set of pending signals. +.IP b) +If the signal handler was installed by a call to \fBsigaction\fP(2) that +specified the \fBSA_ONSTACK\fP flag and the thread has defined an alternate +signal stack (using \fBsigaltstack\fP(2)), then that stack is installed. +.IP c) +Various pieces of signal\-related context are saved into a special frame that +is created on the stack. The saved information includes: +.RS +.IP + 2 +the program counter register (i.e., the address of the next instruction in +the main program that should be executed when the signal handler returns); +.IP + +architecture\-specific register state required for resuming the interrupted +program; +.IP + +the thread's current signal mask; +.IP + +the thread's alternate signal stack settings. +.RE +.IP +(If the signal handler was installed using the \fBsigaction\fP(2) +\fBSA_SIGINFO\fP flag, then the above information is accessible via the +\fIucontext_t\fP object that is pointed to by the third argument of the signal +handler.) +.IP d) +Any signals specified in \fIact\->sa_mask\fP when registering the handler +with \fBsigprocmask\fP(2) are added to the thread's signal mask. The signal +being delivered is also added to the signal mask, unless \fBSA_NODEFER\fP was +specified when registering the handler. These signals are thus blocked +while the handler executes. +.RE +.IP 2. +The kernel constructs a frame for the signal handler on the stack. The +kernel sets the program counter for the thread to point to the first +instruction of the signal handler function, and configures the return +address for that function to point to a piece of user\-space code known as +the signal trampoline (described in \fBsigreturn\fP(2)). +.IP 3. +The kernel passes control back to user\-space, where execution commences at +the start of the signal handler function. +.IP 4. +When the signal handler returns, control passes to the signal trampoline +code. +.IP 5. +The signal trampoline calls \fBsigreturn\fP(2), a system call that uses the +information in the stack frame created in step 1 to restore the thread to +its state before the signal handler was called. The thread's signal mask +and alternate signal stack settings are restored as part of this procedure. +Upon completion of the call to \fBsigreturn\fP(2), the kernel transfers control +back to user space, and the thread recommences execution at the point where +it was interrupted by the signal handler. +.PP +Note that if the signal handler does not return (e.g., control is +transferred out of the handler using \fBsiglongjmp\fP(3), or the handler +executes a new program with \fBexecve\fP(2)), then the final step is not +performed. In particular, in such scenarios it is the programmer's +responsibility to restore the state of the signal mask (using +\fBsigprocmask\fP(2)), if it is desired to unblock the signals that were +blocked on entry to the signal handler. (Note that \fBsiglongjmp\fP(3) may or +may not restore the signal mask, depending on the \fIsavesigs\fP value that was +specified in the corresponding call to \fBsigsetjmp\fP(3).) +.PP +.\" +From the kernel's point of view, execution of the signal handler code is +exactly the same as the execution of any other user\-space code. That is to +say, the kernel does not record any special state information indicating +that the thread is currently excuting inside a signal handler. All +necessary state information is maintained in user\-space registers and the +user\-space stack. The depth to which nested signal handlers may be invoked +is thus limited only by the user\-space stack (and sensible software +design!). +.SS 標準シグナル +Linux supports the standard signals listed below. The second column of the +table indicates which standard (if any) specified the signal: "P1990" +indicates that the signal is described in the original POSIX.1\-1990 +standard; "P2001" indicates that the signal was added in SUSv2 and +POSIX.1\-2001. +.TS +l c c l +____ +lB c c l. +シグナル 標準 動作 コメント +SIGABRT P1990 Core \fBabort\fP(3) からの中断 (Abort) シグナル +SIGALRM P1990 Term \fBalarm\fP(2) からのタイマーシグナル +SIGBUS P2001 Core バスエラー (不正なメモリーアクセス) +SIGCHLD P1990 Ign 子プロセスの一時停止 (stop) または終了 +SIGCLD \- Ign \fBSIGCHLD\fP と同義 +SIGCONT P1990 Cont 一時停止 (stop) からの再開 +SIGEMT \- Term Emulator trap +SIGFPE P1990 Core 浮動小数点例外 +SIGHUP P1990 Term 制御端末(controlling terminal)のハングアップ検出、 + または制御しているプロセスの死 +SIGILL P1990 Core 不正な命令 +SIGINFO \- \fBSIGPWR\fP と同義 +SIGINT P1990 Term キーボードからの割り込み (Interrupt) +SIGIO \- Term 入出力が可能になった (4.2BSD) +SIGIOT \- Core IOT トラップ。 \fBSIGABRT\fP と同義 +SIGKILL P1990 Term Kill シグナル +SIGLOST \- Term ファイルロックが失われた (未使用) +SIGPIPE P1990 Term パイプ破壊: + readers; see \fBpipe\fP(7) +SIGPOLL P2001 Term ポーリング可能なイベント (Sys V); + \fBSIGIO\fP と同義 +SIGPROF P2001 Term profiling タイマーの時間切れ +SIGPWR \- Term 電源喪失 (Power failure) (System V) +SIGQUIT P1990 Core キーボードによる中止 (Quit) +SIGSEGV P1990 Core 不正なメモリー参照 +SIGSTKFLT \- Term 数値演算プロセッサにおけるスタックフォルト (未使用) +SIGSTOP P1990 Stop プロセスの一時停止 (stop) +SIGTSTP P1990 Stop 端末より入力された一時停止 (stop) +SIGSYS P2001 Core Bad system call (SVr4); + see also \fBseccomp\fP(2) +SIGTERM P1990 Term 終了 (termination) シグナル +SIGTRAP P2001 Core トレース/ブレークポイント トラップ +SIGTTIN P1990 Stop バックグランドプロセスの端末入力 +SIGTTOU P1990 Stop バックグランドプロセスの端末出力 +SIGUNUSED \- Core \fBSIGSYS\fP と同義 +SIGURG P2001 Ign ソケットの緊急事態 (urgent condition) (4.2BSD) +SIGUSR1 P1990 Term ユーザー定義シグナル 1 +SIGUSR2 P1990 Term ユーザー定義シグナル 2 +SIGVTALRM P2001 Term 仮想アラームクロック (4.2BSD) +SIGXCPU P2001 Core CPU時間制限超過 (4.2BSD); + see \fBsetrlimit\fP(2) +SIGXFSZ P2001 Core ファイルサイズ制限の超過 (4.2BSD); + see \fBsetrlimit\fP(2) +SIGWINCH \- Ign ウィンドウ リサイズ シグナル (4.3BSD, Sun) +.TE +.PP +シグナル \fBSIGKILL\fP と \fBSIGSTOP\fP はキャッチ、ブロック、無視できない。 +.PP +Linux 2.2 以前では、 \fBSIGSYS\fP, \fBSIGXCPU\fP, \fBSIGXFSZ\fP および SPARC と MIPS +以外のアーキテクチャーでの \fBSIGBUS\fP のデフォルトの振る舞いは (コアダンプ出力なしの) プロセス終了であった。 (他の UNIX +システムにも \fBSIGXCPU\fP と \fBSIGXFSZ\fP のデフォルトの動作がコアダンプなしのプロセス終了のものがある。) Linux 2.4 +では、POSIX.1\-2001 での要求仕様に準拠して、 これらのシグナルで、プロセスを終了させ、コアダンプを出力する ようになっている。 +.PP +\fBSIGEMT\fP は POSIX.1\-2001 に規定されていないが、 その他の多くの UNIX システムに存在する。 +デフォルトの動作は多くの場合、コアダンプ出力を伴うプロセスの終了である。 +.PP +\fBSIGPWR\fP は (POSIX.1\-2001 に規定されていないが) このシグナルが存在する 他の UNIX +システムでは多くの場合、デフォルト動作は無視である。 +.PP +.\" +\fBSIGIO\fP は (POSIX.1\-2001 に規定されていないが) いくつかの他の UNIX システムでは デフォルト動作は無視である。 +.SS "Queueing and delivery semantics for standard signals" +If multiple standard signals are pending for a process, the order in which +the signals are delivered is unspecified. +.PP +.\" +Standard signals do not queue. If multiple instances of a standard signal +are generated while that signal is blocked, then only one instance of the +signal is marked as pending (and the signal will be delivered just once when +it is unblocked). In the case where a standard signal is already pending, +the \fIsiginfo_t\fP structure (see \fBsigaction\fP(2)) associated with that +signal is not overwritten on arrival of subsequent instances of the same +signal. Thus, the process will receive the information associated with the +first instance of the signal. +.SS "Signal numbering for standard signals" +The numeric value for each signal is given in the table below. As shown in +the table, many signals have different numeric values on different +architectures. The first numeric value in each table row shows the signal +number on x86, ARM, and most other architectures; the second value is for +Alpha and SPARC; the third is for MIPS; and the last is for PARISC. A dash +(\-) denotes that a signal is absent on the corresponding architecture. +.TS +l c c c c l +l c c c c l +______ +lB c c c c l. +シグナル x86/ARM Alpha/ MIPS PARISC Notes + most others SPARC +SIGHUP \01 \01 \01 \01 +SIGINT \02 \02 \02 \02 +SIGQUIT \03 \03 \03 \03 +SIGILL \04 \04 \04 \04 +SIGTRAP \05 \05 \05 \05 +SIGABRT \06 \06 \06 \06 +SIGIOT \06 \06 \06 \06 +SIGBUS \07 10 10 10 +SIGEMT \- \07 \07 \- +SIGFPE \08 \08 \08 \08 +SIGKILL \09 \09 \09 \09 +SIGUSR1 10 30 16 16 +SIGSEGV 11 11 11 11 +SIGUSR2 12 31 17 17 +SIGPIPE 13 13 13 13 +SIGALRM 14 14 14 14 +SIGTERM 15 15 15 15 +SIGSTKFLT 16 \- \- \07 +SIGCHLD 17 20 18 18 +SIGCLD \- \- 18 \- +SIGCONT 18 19 25 26 +SIGSTOP 19 17 23 24 +SIGTSTP 20 18 24 25 +SIGTTIN 21 21 26 27 +SIGTTOU 22 22 27 28 +SIGURG 23 16 21 29 +SIGXCPU 24 24 30 12 +SIGXFSZ 25 25 31 30 +SIGVTALRM 26 26 28 20 +SIGPROF 27 27 29 21 +SIGWINCH 28 28 20 23 +SIGIO 29 23 22 22 +SIGPOLL Same as SIGIO +SIGPWR 30 29/\- 19 19 +SIGINFO \- 29/\- \- \- +SIGLOST \- \-/29 \- \- +SIGSYS 31 12 12 31 +SIGUNUSED 31 \- \- 31 +.TE +.PP +Note the following: +.IP * 3 +Where defined, \fBSIGUNUSED\fP is synonymous with \fBSIGSYS\fP. Since glibc 2.26, +\fBSIGUNUSED\fP is no longer defined on any architecture. +.IP * +.\" +Signal 29 is \fBSIGINFO\fP/\fBSIGPWR\fP (synonyms for the same value) on Alpha but +\fBSIGLOST\fP on SPARC. +.SS リアルタイムシグナル +Starting with version 2.2, Linux supports real\-time signals as originally +defined in the POSIX.1b real\-time extensions (and now included in +POSIX.1\-2001). The range of supported real\-time signals is defined by the +macros \fBSIGRTMIN\fP and \fBSIGRTMAX\fP. POSIX.1\-2001 requires that an +implementation support at least \fB_POSIX_RTSIG_MAX\fP (8) real\-time signals. +.PP +The Linux kernel supports a range of 33 different real\-time signals, +numbered 32 to 64. However, the glibc POSIX threads implementation +internally uses two (for NPTL) or three (for LinuxThreads) real\-time signals +(see \fBpthreads\fP(7)), and adjusts the value of \fBSIGRTMIN\fP suitably (to 34 +or 35). Because the range of available real\-time signals varies according +to the glibc threading implementation (and this variation can occur at run +time according to the available kernel and glibc), and indeed the range of +real\-time signals varies across UNIX systems, programs should \fInever refer +to real\-time signals using hard\-coded numbers\fP, but instead should always +refer to real\-time signals using the notation \fBSIGRTMIN\fP+n, and include +suitable (run\-time) checks that \fBSIGRTMIN\fP+n does not exceed \fBSIGRTMAX\fP. +.PP +標準シグナルと異なり、リアルタイムシグナルには 事前に定義された意味はない。 リアルタイムシグナルの全部をアプリケーションで定義した用途に使える。 +.PP +ハンドリングしないリアルタイムシグナルのデフォルトの動作は 受信したプロセスの終了である。 +.PP +リアルタイムシグナルは以下の特徴がある: +.IP 1. 4 +リアルタイムシグナルは複数の実体をキューに入れることができる。 一方、標準シグナルの場合、そのシグナルがブロックされている間に +同じシグナルの複数のインスタンスが配送されても、 1 つだけがキューに入れられる。 +.IP 2. 4 +シグナルが \fBsigqueue\fP(3) を用いて送信された場合、 付属データ (整数かポインター) をシグナルと共に送信できる。 受信側プロセスが +\fBsigaction\fP(2) に \fBSA_SIGINFO\fP フラグを指定してシグナルハンドラーを設定した場合、 このデータは +\fIsiginfo_t\fP 構造体の \fIsi_value\fP フィールド経由でハンドラーの第 2 引き数として渡され、 利用することができる。 +さらに、この構造体の \fIsi_pid\fP と \fIsi_uid\fP フィールドでシグナルを送信したプロセスの PID と実ユーザー ID を +得ることができる。 +.IP 3. 4 +リアルタイムシグナルでは配送される順序が保証される。 同じタイプのリアルタイムシグナルは送信された順番に到着する。 +異なるリアルタイムシグナルが一つのプロセスに送信された場合、 番号の小さいシグナルから先に到着する。 +(つまり小さい番号のシグナルが高い優先順位を持つ。) 対照的に、一つのプロセスに対して複数の標準シグナルが処理待ちとなった場合、 +これらのシグナルが配送される順序は不定である。 +.PP +一つのプロセスに対して標準シグナルとリアルタイムシグナルの両方が 処理待ちの場合、POSIX はどちらが先に配送されるかを規定していない。 Linux +では、他の多くの実装と同様、このような場合には 標準シグナルが優先される。 +.PP +POSIX によれば、1 プロセス毎に最低 \fB_POSIX_SIGQUEUE_MAX\fP (32) +個のリアルタイムシグナルをキューに入れられるべきとしている。 しかし、 Linux では違った実装になっている。カーネル 2.6.7 までは +(2.6.7 を含む)、全プロセスでキューに入っているリアルタイムシグナル の数の合計についてシステム全体での制限がある。 この制限は +\fI/proc/sys/kernel/rtsig\-max\fP ファイルで見ることができ、 (権限があれば) 変更もできる。 関係するファイルとして、 +\fI/proc/sys/kernel/rtsig\-nr\fP を見ることで、いくつのリアルタイムシグナルが現在キューに入っているかを 知ることができる。 +Linux 2.6.8 で、これらの \fI/proc\fP 経由のインターフェースは、 \fBRLIMIT_SIGPENDING\fP +リソース制限に置き換えられた。 これは、キューに入るシグナル数に関してユーザー単位に 上限を指定するものである。 詳しくは +\fBsetrlimit\fP(2) を参照。 +.PP +The addition of real\-time signals required the widening of the signal set +structure (\fIsigset_t\fP) from 32 to 64 bits. Consequently, various system +calls were superseded by new system calls that supported the larger signal +sets. The old and new system calls are as follows: +.TS +lb lb +l l. +Linux 2.0 and earlier Linux 2.2 and later +\fBsigaction\fP(2) \fBrt_sigaction\fP(2) +\fBsigpending\fP(2) \fBrt_sigpending\fP(2) +\fBsigprocmask\fP(2) \fBrt_sigprocmask\fP(2) +\fBsigreturn\fP(2) \fBrt_sigreturn\fP(2) +\fBsigsuspend\fP(2) \fBrt_sigsuspend\fP(2) +\fBsigtimedwait\fP(2) \fBrt_sigtimedwait\fP(2) +.TE +.\" +.SS シグナルハンドラーによるシステムコールやライブラリ関数への割り込み +システムコールやライブラリが停止 (block) している間にシグナルハンドラーが 起動されると、以下のどちらかとなる。 +.IP * 2 +シグナルが返った後、呼び出しは自動的に再スタートされる。 +.IP * +呼び出しはエラー \fBEINTR\fP で失敗する。 +.PP +これらの二つの挙動のうちどちらが起こるかは、インターフェイスにより依存し、 シグナルハンドラーが \fBSA_RESTART\fP フラグ +(\fBsigaction\fP(2) 参照) を使って設定されていたかにも依存する。 詳細は UNIX システムによって異なる。 Linux +における詳細を以下で説明する。 +.PP +.\" The following system calls use ERESTARTSYS, +.\" so that they are restartable +If a blocked call to one of the following interfaces is interrupted by a +signal handler, then the call is automatically restarted after the signal +handler returns if the \fBSA_RESTART\fP flag was used; otherwise the call fails +with the error \fBEINTR\fP: +.IP * 2 +\fBread\fP(2), \fBreadv\fP(2), \fBwrite\fP(2), \fBwritev\fP(2), and \fBioctl\fP(2) calls +on "slow" devices. A "slow" device is one where the I/O call may block for +an indefinite time, for example, a terminal, pipe, or socket. If an I/O +call on a slow device has already transferred some data by the time it is +interrupted by a signal handler, then the call will return a success status +(normally, the number of bytes transferred). Note that a (local) disk is +not a slow device according to this definition; I/O operations on disk +devices are not interrupted by signals. +.IP * +停止 (block) する可能性のある \fBopen\fP(2) (例えば、FIFO のオープン時; \fBfifo\fP(7) 参照)。 +.IP * +\fBwait\fP(2), \fBwait3\fP(2), \fBwait4\fP(2), \fBwaitid\fP(2), \fBwaitpid\fP(2). +.IP * +.\" If a timeout (setsockopt()) is in effect on the socket, then these +.\" system calls switch to using EINTR. Consequently, they and are not +.\" automatically restarted, and they show the stop/cont behavior +.\" described below. (Verified from 2.6.26 source, and by experiment; mtk) +.\" FIXME What about sendmmsg()? +ソケットインターフェイス: \fBaccept\fP(2), \fBconnect\fP(2), \fBrecv\fP(2), \fBrecvfrom\fP(2), +\fBrecvmmsg\fP(2), \fBrecvmsg\fP(2), \fBsend\fP(2), \fBsendto\fP(2), \fBsendmsg\fP(2). +但し、ソケットにタイムアウトが設定されていない場合 (下記参照)。 +.IP * +ファイルロック用インターフェイス: \fBflock\fP(2), \fBfcntl\fP(2) の \fBF_SETLKW\fP と \fBF_OFD_SETLKW\fP +操作。 +.IP * +POSIX メッセージキューインターフェイス: \fBmq_receive\fP(3), \fBmq_timedreceive\fP(3), +\fBmq_send\fP(3), \fBmq_timedsend\fP(3). +.IP * +.\" commit 72c1bbf308c75a136803d2d76d0e18258be14c7a +\fBfutex\fP(2) \fBFUTEX_WAIT\fP (Linux 2.6.22 以降; それ以前は常に \fBEINTR\fP で失敗していた)。 +.IP * +\fBgetrandom\fP(2). +.IP * +\fBpthread_mutex_lock\fP(3), \fBpthread_cond_wait\fP(3) と関連 API。 +.IP * +\fBfutex\fP(2) \fBFUTEX_WAIT_BITSET\fP. +.IP * +.\" as a consequence of the 2.6.22 changes in the futex() implementation +POSIX セマフォインターフェイス: \fBsem_wait\fP(3), \fBsem_timedwait\fP(3) (Linux 2.6.22 以降; +それ以前は常に \fBEINTR\fP で失敗していた)。 +.IP * +.\" commit 1ca39ab9d21ac93f94b9e3eb364ea9a5cf2aba06 +\fBread\fP(2) from an \fBinotify\fP(7) file descriptor (since Linux 3.8; +beforehand, always failed with \fBEINTR\fP). +.PP +.\" These are the system calls that give EINTR or ERESTARTNOHAND +.\" on interruption by a signal handler. +以下のインターフェイスは、 \fBSA_RESTART\fP を使っているどうかに関わらず、シグナルハンドラーにより割り込まれた後、 +再スタートすることは決してない。 これらは、シグナルハンドラーにより割り込まれると、常にエラー \fBEINTR\fP で失敗する。 +.IP * 2 +\fBsetsockopt\fP(2) を使ってタイムアウト (\fBSO_RCVTIMEO\fP) が設定されている「入力」ソケットインターフェース: +\fBaccept\fP(2), \fBrecv\fP(2), \fBrecvfrom\fP(2), \fBrecvmmsg\fP(2) (NULL 以外の +\fItimeout\fP 引き数も指定されている場合), \fBrecvmsg\fP(2) +.IP * +.\" FIXME What about sendmmsg()? +"Output" socket interfaces, when a timeout (\fBSO_RCVTIMEO\fP) has been set on +the socket using \fBsetsockopt\fP(2): \fBconnect\fP(2), \fBsend\fP(2), \fBsendto\fP(2), +and \fBsendmsg\fP(2). +.IP * +シグナル待ちに使われるインターフェイス: \fBpause\fP(2), \fBsigsuspend\fP(2), \fBsigtimedwait\fP(2), +\fBsigwaitinfo\fP(2). +.IP * +ファイルディスクリプター多重インターフェイス: \fBepoll_wait\fP(2), \fBepoll_pwait\fP(2), \fBpoll\fP(2), +\fBppoll\fP(2), \fBselect\fP(2), \fBpselect\fP(2). +.IP * +.\" On some other systems, SA_RESTART does restart these system calls +System V IPC インターフェイス: \fBmsgrcv\fP(2), \fBmsgsnd\fP(2), \fBsemop\fP(2), +\fBsemtimedop\fP(2). +.IP * +スリープ用のインターフェイス: \fBclock_nanosleep\fP(2), \fBnanosleep\fP(2), \fBusleep\fP(3). +.IP * +\fBio_getevents\fP(2). +.PP +\fBsleep\fP(3) 関数も、ハンドラーにより割り込まれた場合、決して再スタートされることはない。 しかし、成功となり、残っている停止時間を返す。 +.SS 一時停止シグナルによるシステムコールやライブラリ関数への割り込み +Linux では、シグナルハンドラーが設定されていない場合でも、 いくつかのブロッキング型のインターフェイスは、 プロセスが一時停止 (stop) +シグナルの一つにより停止され、 \fBSIGCONT\fP により再開された後に、エラー \fBEINTR\fP で失敗する可能性がある。 この挙動は +POSIX.1 で認められておらず、他のシステムでは起こらない。 +.PP +この挙動を示す Linux のインターフェイスは以下の通りである。 +.IP * 2 +\fBsetsockopt\fP(2) を使ってタイムアウト (\fBSO_RCVTIMEO\fP) が設定されている「入力」ソケットインターフェース: +\fBaccept\fP(2), \fBrecv\fP(2), \fBrecvfrom\fP(2), \fBrecvmmsg\fP(2) (NULL 以外の +\fItimeout\fP 引き数も指定されている場合), \fBrecvmsg\fP(2) +.IP * +.\" FIXME What about sendmmsg()? +"Output" socket interfaces, when a timeout (\fBSO_RCVTIMEO\fP) has been set on +the socket using \fBsetsockopt\fP(2): \fBconnect\fP(2), \fBsend\fP(2), \fBsendto\fP(2), +and \fBsendmsg\fP(2), if a send timeout (\fBSO_SNDTIMEO\fP) has been set. +.IP * 2 +\fBepoll_wait\fP(2), \fBepoll_pwait\fP(2). +.IP * +\fBsemop\fP(2), \fBsemtimedop\fP(2). +.IP * +\fBsigtimedwait\fP(2), \fBsigwaitinfo\fP(2). +.IP * +.\" commit 1ca39ab9d21ac93f94b9e3eb364ea9a5cf2aba06 +Linux 3.7 and earlier: \fBread\fP(2) from an \fBinotify\fP(7) file descriptor +.IP * +Linux 2.6.21 以前: \fBfutex\fP(2) \fBFUTEX_WAIT\fP, \fBsem_timedwait\fP(3), +\fBsem_wait\fP(3). +.IP * +Linux 2.6.8 以前: \fBmsgrcv\fP(2), \fBmsgsnd\fP(2). +.IP * +Linux 2.4 以前: \fBnanosleep\fP(2). +.SH 準拠 +POSIX.1 (注記した内容以外)。 +.SH 注意 +For a discussion of async\-signal\-safe functions, see \fBsignal\-safety\fP(7). +.PP +The \fI/proc/[pid]/task/[tid]/status\fP file contains various fields that show +the signals that a thread is blocking (\fISigBlk\fP), catching (\fISigCgt\fP), or +ignoring (\fISigIgn\fP). (The set of signals that are caught or ignored will +be the same across all threads in a process.) Other fields show the set of +pending signals that are directed to the thread (\fISigPnd\fP) as well as the +set of pending signals that are directed to the process as a whole +(\fIShdPnd\fP). The corresponding fields in \fI/proc/[pid]/status\fP show the +information for the main thread. See \fBproc\fP(5) for further details. +.SH バグ +There are six signals that can be delivered as a consequence of a hardware +exception: \fBSIGBUS\fP, \fBSIGEMT\fP, \fBSIGFPE\fP, \fBSIGILL\fP, \fBSIGSEGV\fP, and +\fBSIGTRAP\fP. Which of these signals is delivered, for any given hardware +exception, is not documented and does not always make sense. +.PP +For example, an invalid memory access that causes delivery of \fBSIGSEGV\fP on +one CPU architecture may cause delivery of \fBSIGBUS\fP on another +architecture, or vice versa. +.PP +For another example, using the x86 \fIint\fP instruction with a forbidden +argument (any number other than 3 or 128) causes delivery of \fBSIGSEGV\fP, +even though \fBSIGILL\fP would make more sense, because of how the CPU reports +the forbidden operation to the kernel. +.SH 関連項目 +\fBkill\fP(1), \fBclone\fP(2), \fBgetrlimit\fP(2), \fBkill\fP(2), +\fBpidfd_send_signal\fP(2), \fBrestart_syscall\fP(2), \fBrt_sigqueueinfo\fP(2), +\fBsetitimer\fP(2), \fBsetrlimit\fP(2), \fBsgetmask\fP(2), \fBsigaction\fP(2), +\fBsigaltstack\fP(2), \fBsignal\fP(2), \fBsignalfd\fP(2), \fBsigpending\fP(2), +\fBsigprocmask\fP(2), \fBsigreturn\fP(2), \fBsigsuspend\fP(2), \fBsigwaitinfo\fP(2), +\fBabort\fP(3), \fBbsd_signal\fP(3), \fBkillpg\fP(3), \fBlongjmp\fP(3), +\fBpthread_sigqueue\fP(3), \fBraise\fP(3), \fBsigqueue\fP(3), \fBsigset\fP(3), +\fBsigsetops\fP(3), \fBsigvec\fP(3), \fBsigwait\fP(3), \fBstrsignal\fP(3), +\fBswapcontext\fP(3), \fBsysv_signal\fP(3), \fBcore\fP(5), \fBproc\fP(5), \fBnptl\fP(7), +\fBpthreads\fP(7), \fBsigevent\fP(7) +.SH この文書について +この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は +\%https://www.kernel.org/doc/man\-pages/ に書かれている。