The following program demonstrates the use of the sigsuspend system call. sigsuspend atomically changes the process's (thread's) signal mask and suspends execution until the kernel delivers a signal (for an unblocked signal) that would invoke one of the program's handlers or terminate the process. On return, sigsuspend restores the prior signal mask.
The program itself sets a mask to block SIGINT and SIGQUIT, establishes a signal handler for these two signals, and then loops until it handles a SIGQUIT. We treat the body of the loop as a critical section that runs uninterrupted by these two signals. At the bottom of the loop, we use sigsuspend to unblock SIGINT and SIGQUIT so that the process can either service these pending signals, or wait until a signal occurs.
The complete source code and Makefile is available as a zip file.