sigwaitinfo


The following program demonstrates the use of the sigwaitinfo system call. sigwaitinfo suspends the execution of the calling thread until one of the signals that it specifies becomes pending. When one of the signals in the specified set becomes pending, rather than invoke a signal handler, sigwaitinfo itself "handles" the signal and returns information about the signal. In other words, sigwaitinfo allows us to synchronously handle the delivery of signals, which tends to be simpler than splitting logic between a handler function and the main program.

The program itself uses sigprocmask to block all signals (sigprocmask silently ignores SIGKILL and SIGSTOP, which cannot be blocked, caught, or ignored). The program then uses sigwaitinfo to wait for a signal to become pending. If this signal is either SIGINT or SIGTERM, the process terminates; otherwise, the program prints information about the signal and resumes calling sigwaitinfo to wait for another signal to become pending.

sigwaitinfo.c