A developer is reviewing the signal-handling code of a single-threaded POSIX utility. Match each interface to its specific responsibility. Distinguish changing delivery policy from constructing a set in memory and from selecting the response to delivery.
Examines or establishes the response associated with a particular signal
Examines or changes which signals are blocked during ordinary execution
Initializes a set object in memory so that it contains no signals
Atomically substitutes a temporary blocked set and waits for a caught or terminating signal
sigprocmask()
sigemptyset()
sigsuspend()
sigaction()
Unlock full course notes by signing up
Counting deliveries rather than generations
A single-threaded Linux process has returning handlers installed for the standard signals SIGUSR1 and SIGUSR2, with neither signal initially pending. It blocks both signals, receives 9 generations of SIGUSR1 and 4 of SIGUSR2, then unblocks both and allows every pending handler to finish. It next blocks only SIGUSR1, receives 6 more generations of that signal, then unblocks it and again allows delivery to finish. Each batch finishes entirely while its relevant signals are blocked. The handlers neither generate signals nor change dispositions, and no other signals occur. How many handler invocations occur in total? Answer in invocations, as an integer.
Following signal state into a replacement program
A single-threaded Linux launcher has a handler installed for SIGUSR1 and ignores SIGUSR2. It blocks SIGUSR1 and has one pending SIGUSR1.
The launcher successfully calls fork to create a child. The child then successfully calls execve to replace its program. No new signals are generated, and neither the child nor the replacement program explicitly changes any signal settings.
Complete the child's signal state immediately after fork and immediately after execve, before the replacement program executes its own setup. Enter handler, default, or ignore for action cells, and yes or no for the other cells.
Repairing the check-then-sleep race
A single-threaded POSIX program initializes a static volatile sig_atomic_t flag named ready to 0. Its installed SIGUSR1 handler assigns 1 to that flag and returns. SIGUSR1 is initially unblocked. A sender will generate exactly one notification after handler installation, and no other signals occur. The program waits using this code:
Which statements correctly describe this code or a repair? Select all that apply. Assume all setup calls succeed and every supplied signal set is valid.
Preserving progress after interrupted reads
A Linux data collector reads a 960-byte record from a blocking pipe. Its signal handler returns normally, preserves errno, and does not access the pipe or buffer. The handler was installed without SA_RESTART.
The proposed recovery code is below. The buffer holds 960 bytes, the required declarations and headers are supplied, and errno initially equals EINTR.
The first five calls produce these observed results. Each failure is caused by a caught signal before that call transfers any bytes.