.\" 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/ に書かれている。