Skip to content

sigprocmask()

Purpose

sigprocmask() changes the calling thread's signal mask.

It is commonly used before signalfd() so selected signals are delivered through a file descriptor instead of traditional handlers.

#include <signal.h>

Prototype

int sigprocmask(int how, const sigset_t *set, sigset_t *oldset);

Minimal Example

sigset_t mask;

sigemptyset(&mask);
sigaddset(&mask, SIGINT);
sigaddset(&mask, SIGTERM);

if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
    perror("sigprocmask");
    return -1;
}

Common Pitfalls

  • Creating a signalfd without blocking the same signals first.
  • Blocking signals globally without documenting shutdown behavior.
  • Confusing process signal disposition with per-thread signal masks.