sigismember() — Test if a signal is in a signal mask

Standards

Standards / Extensions C or C++ Dependencies

POSIX.1
XPG4
XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define _POSIX_SOURCE
#include <signal.h>

int sigismember(const sigset_t *set, int signal);

General description

Tests whether a specified signal number signal is a member of a signal set set.

sigismember() is part of a family of functions that manipulate signal sets. Signal sets are data objects that let a process keep track of groups of signals. For example, a process can create one signal set to record which signals it is blocking, and another signal set to record which signals are pending. Signal sets are used to manipulate groups of signals used by other functions (such as sigprocmask()) or to examine signal sets returned by other functions (such as sigpending()).

Applications should call either sigemptyset() or sigfillset() at least once for each object of type sigset_t prior to any other use of that object. If such an object is not initialized in this way, but is nonetheless supplied as an argument to any of pthread_sigmask(), sigaction(), sigaddset(), sigdelset(), sigismember(), sigpending(), sigprocmask(), sigsuspend(), sigtimedwait(), sigwait(), or sigwaitinfo(), the results are undefined.

Usage note

The use of the SIGTHSTOP and SIGTHCONT signal is not supported with this function.

Returned value

sigismember() returns 1 if signal is in set, and it returns 0 if it is not.

If unsuccessful, sigismember() returns -1 and sets errno to one of the following values:
Error Code
Description
EINVAL
The value of signal is not one of the supported signals.

Example

CELEBS19
⁄* CELEBS19

   This example tests signals.

 *⁄
#define _POSIX_SOURCE
#include <stdio.h>
#include <signal.h>

void check(sigset_t set, int signum, char *signame) {
  printf("%-8s is ", signame);
  if (!sigismember(&set, signum))
    printf("not ");
  puts("in the set");
}

main() {
  sigset_t sigset;

  sigemptyset(&sigset);
  sigaddset(&sigset, SIGUSR1);
  sigaddset(&sigset, SIGKILL);
  sigaddset(&sigset, SIGCHLD);

  check(sigset, SIGUSR1, "SIGUSR1");
  check(sigset, SIGUSR2, "SIGUSR2");
  check(sigset, SIGFPE,  "SIGFPE");
  check(sigset, SIGKILL, "SIGKILL");
}
Output
SIGUSR1  is in the set
SIGUSR2  is not in the set
SIGFPE   is not in the set
SIGKILL  is in the set

Related information