Scroll to navigation

SIGPROCMASK(2) Linux Programmer's Manual SIGPROCMASK(2)

名前

sigprocmask, rt_sigprocmask - 禁止するシグナルの確認と変更

書式

#include <signal.h>

/* Prototype for the glibc wrapper function */
int sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
/* Prototype for the underlying system call */
int rt_sigprocmask(int how, const kernel_sigset_t *set,
                   kernel_sigset_t *oldset, size_t sigsetsize);
/* Prototype for the legacy system call (deprecated) */
int sigprocmask(int how, const old_kernel_sigset_t *set,
                old_kernel_sigset_t *oldset);

glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):

sigprocmask(): _POSIX_C_SOURCE

説明

sigprocmask() を使うと、呼び出したスレッドのシグナルマスクの取得/変更ができる。 シグナルマスクは、呼び出し元に対して現在配送が禁止されているシグナルの 集合のことである (詳細については signal(7) も参照のこと)。

このコールの動作は how の値によって決まる:

禁止されたシグナルの集合は現在の値と set 引数を結合したものとなる。
現在禁止されているシグナルの集合から set にあるシグナルを取り除く。禁止されていないシグナルを取り除こうと することも認められている。
禁止されているシグナルの集合に set 引数を設定する。

oldset が NULL でなければ、シグナルマスクの今までの値を oldset に格納する。

set が NULL であれば、シグナルマスクは変更されない (すなわち、 how は無視される)。 set の値にかかわらず、現在のシグナルマスクの値は oldset に入れて返される (但し、 oldset が NULL でない場合)。

A set of functions for modifying and inspecting variables of type sigset_t ("signal sets") is described in sigsetops(3).

マルチスレッドのプロセスで sigprocmask() を使用した場合の動作は規定されていない。 pthread_sigmask(3) を参照のこと。

返り値

sigprocmask() は成功した場合 0 を返す。 エラーの場合、 -1 を返し、 errno にエラーの原因を示す値を設定する。

エラー

引数 setoldset がプロセスに割り当てられたアドレス空間の外を指している。
Either the value specified in how was invalid or the kernel does not support the size passed in sigsetsize.

準拠

POSIX.1-2001, POSIX.1-2008.

注意

SIGKILLSIGSTOP を禁止することはできない。 禁止しようとしても黙って無視される。

プロセス内の各スレッドはそれぞれ専用のシグナルマスクを持つ。

fork(2) 経由で作成された子プロセスは親プロセスのシグナルマスクのコピーを継承する。 execve(2) の前後でシグナルマスクは保持される。

シグナル SIGBUS, SIGFPE, SIGILL, SIGSEGV が禁止されている間に生成された場合で、 そのシグナルが kill(2), sigqueue(3), raise(3) によって生成されたものでないときには、 その後の動作は未定義である。

シグナル集合の操作に関する詳細は sigsetops(3) を参照のこと。

Note that it is permissible (although not very useful) to specify both set and oldset as NULL.

C ライブラリとカーネルの違い

The kernel's definition of sigset_t differs in size from that used by the C library. In this manual page, the former is referred to as kernel_sigset_t (it is nevertheless named sigset_t in the kernel sources).

The glibc wrapper function for sigprocmask() silently ignores attempts to block the two real-time signals that are used internally by the NPTL threading implementation. See nptl(7) for details.

The original Linux system call was named sigprocmask(). However, with the addition of real-time signals in Linux 2.2, the fixed-size, 32-bit sigset_t (referred to as old_kernel_sigset_t in this manual page) type supported by that system call was no longer fit for purpose. Consequently, a new system call, rt_sigprocmask(), was added to support an enlarged sigset_t type (referred to as kernel_sigset_t in this manual page). The new system call takes a fourth argument, size_t sigsetsize, which specifies the size in bytes of the signal sets in set and oldset. This argument is currently required to have a fixed architecture specific value (equal to sizeof(kernel_sigset_t)).

The glibc sigprocmask() wrapper function hides these details from us, transparently calling rt_sigprocmask() when the kernel provides it.

関連項目

kill(2), pause(2), sigaction(2), signal(2), sigpending(2), sigsuspend(2), pthread_sigmask(3), sigqueue(3), sigsetops(3), signal(7)

この文書について

この man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。

2017-09-15 Linux