Skip to content
Advertisement

What are the relation and difference between a signal mask and a signal set?

From APUE

Each process has a signal mask that defines the set of signals currently blocked from delivery to that process. We can think of this mask as having one bit for each possible signal. If the bit is on for a given signal, that signal is currently blocked. A process can examine and change its current signal mask by calling sigprocmask, which we describe in Section 10.12.

Since it is possible for the number of signals to exceed the number of bits in an integer, POSIX.1 defines a data type, called sigset_t, that holds a signal set. The signal mask, for example, is stored in one of these signal sets. We describe five functions that operate on signal sets in Section 10.11.

What are the relation and difference between a signal mask and a signal set?

Is a signal mast a datum, and is a signal set an object, as a datum is stored in an object?

What are the differences between, and when shall we use which:

#include <signal.h>
int sigaddset(sigset_t *set, int signo);
int sigdelset(sigset_t *set, int signo);

and

#include <signal.h>
int sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict oset);

Thanks.

Advertisement

Answer

The signal mask is an attribute of a process, the list of signals that are blocked. sigprocmask retrieves and/or updates this attribute of the process.

A signal set is a data type that holds a list of signal numbers. sigaddset and sigdelset are used to modify an object containing this data.

When you want to set or retrieve the signal mask of a process, the sigprocmask() system call takes a parameter whose type is sigset_t* to hold a pointer to this list.

It’s analogous to the relationship between process IDs and pid_t.

So if you want to modify the signal mask of a process, you might do the following:

  1. Call sigprocmask() with a null set and non-null oset parameter to get the current process mask in a sigset_t variable.
  2. Call sigaddset() and/or sigdelset() to add and delete signals from that variable.
  3. Call sigprocmask() with how = SIG_SETMASK and set containing the updated signal set.

If you just want to add or remove signals from the mask, but not both, you can use the SIG_BLOCK and SIG_UNBLOCK operations to do it in a single call to sigprocmask. Just create a signal set containing the signals you want to add or remove, and they’ll be merged with the existing mask.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement