[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions , Volume 2


sigprocmask, sigsetmask, or sigblock Subroutine

Purpose

Sets the current signal mask.

Library

Standard C Library (libc.a)

Syntax

#include <signal.h>


int sigprocmask ( How Set OSet)
int How;
const sigset_t *Set;
sigset *OSet;


int sigsetmask ( SignalMask)
int SignalMask;


int sigblock (SignalMask)
int SignalMask;

Description

Note: The sigprocmask, sigsetmask, and sigblock subroutines must not be used in a multi-threaded application. The sigthreadmask (sigthreadmask Subroutine) subroutine must be used instead.

The sigprocmask subroutine is used to examine or change the signal mask of the calling thread.

The subroutine is used to examine or change the signal mask of the calling process.

Typically, you should use the sigprocmask(SIG_BLOCK) subroutine to block signals during a critical section of code. Then use the sigprocmask(SIG_SETMASK) subroutine to restore the mask to the previous value returned by the sigprocmask(SIG_BLOCK) subroutine.

If there are any pending unblocked signals after the call to the sigprocmask subroutine, at least one of those signals will be delivered before the sigprocmask subroutine returns.

The sigprocmask subroutine does not allow the SIGKILL or SIGSTOP signal to be blocked. If a program attempts to block either signal, the sigprocmask subroutine gives no indication of the error.

Parameters


How Indicates the manner in which the set is changed. It can have one of the following values:

SIG_BLOCK
The resulting set is the union of the current set and the signal set pointed to by the Set parameter.

SIG_UNBLOCK
The resulting set is the intersection of the current set and the complement of the signal set pointed to by the Set parameter.

SIG_SETMASK
The resulting set is the signal set pointed to by the Set parameter.
Set Specifies the signal set. If the value of the Set parameter is not null, it points to a set of signals to be used to change the currently blocked set. If the value of the Set parameter is null, the value of the How parameter is not significant and the process signal mask is unchanged. Thus, the call can be used to inquire about currently blocked signals.
OSet If the OSet parameter is not the null value, the signal mask in effect at the time of the call is stored in the space pointed to by the OSet parameter.
SignalMask Specifies the signal mask of the process.

Compatibility Interfaces

The sigsetmask subroutine allows changing the process signal mask for signal values 1 to 31. This same function can be accomplished for all values with the sigprocmask(SIG_SETMASK) subroutine. The signal of value i will be blocked if the ith bit of SignalMask parameter is set.

Upon successful completion, the sigsetmask subroutine returns the value of the previous signal mask. If the subroutine fails, a value of -1 is returned and the errno global variable is set to indicate the error as in the sigprocmask subroutine.

The sigblock subroutine allows signals with values 1 to 31 to be logically ORed into the current process signal mask. This same function can be accomplished for all values with the sigprocmask(SIG_BLOCK) subroutine. The signal of value i will be blocked, in addition to those currently blocked, if the i-th bit of the SignalMask parameter is set.

It is not possible to block a SIGKILL or SIGSTOP signal using the sigblock or sigsetmask subroutine. This restriction is silently imposed by the system without causing an error to be indicated.

Upon successful completion, the sigblock subroutine returns the value of the previous signal mask. If the subroutine fails, a value of -1 is returned and the errno global variable is set to indicate the error as in the sigprocmask subroutine.

Return Values

Upon completion, a value of 0 is returned. If the sigprocmask subroutine fails, the signal mask of the process is unchanged, a value of -1 is returned, and the global variable errno is set to indicate the error.

Error Codes

The sigprocmask subroutine is unsuccessful if the following is true:

EPERM The user does not have the privilege to change the signal's mask.
EINVAL The value of the How parameter is not equal to one of the defined values.
EFAULT The user's mask is not in the process address space.

Implementation Specifics

This subroutine is part of Base Operating System (BOS) Runtime.

Examples

To set the signal mask to block only the SIGINT signal from delivery, enter:

 

#include <signal.h>
 
int return_value;
sigset_t newset;
sigset_t *newset_p;
 . . .
newset_p = &newset;
sigemptyset(newset_p);
sigaddset(newset_p, SIGINT);
return_value = sigprocmask (SIG_SETMASK, newset_p, NULL);

Implementation Specifics

These subroutines are part of Base Operating System (BOS) Runtime.

Related Information

The kill or killpg subroutine, sigaction, sigvec, or signal (sigaction, sigvec, or signal Subroutine) subroutine, sigaddset, sigdelset, sigemptyset, sigfillset, sigismember (sigemptyset, sigfillset, sigaddset, sigdelset, or sigismember Subroutine) subroutine, sigpause (sigsuspend or sigpause Subroutine) subroutine, sigpending (sigpending Subroutine) subroutine, sigsuspend (sigsuspend or sigpause Subroutine) subroutine.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]