The sigwaitinfo and the sigtimedwait system calls

The sigwaitinfo(2) system call is similar to sigwait: provided with a set of signals to watch out for, the function puts the caller to sleep until any one of those signals (in set) are pending. Here are their prototypes:

#include <signal.h>
int sigwaitinfo(const sigset_t *set, siginfo_t *info);
int sigtimedwait(const sigset_t *set, siginfo_t *info,
const struct timespec *timeout);

In terms of a return, the sigwait API was able to provide us with the signal number of the signal that got delivered to the calling process. However, recall that there is a much more powerful feature of the sigaction(2) API—the ability to return valuable diagnostic and other information within the siginfo_t data structure. Well, that's precisely what the sigwaitinfo(2) system call provides! (We covered the siginfo_t structure and what you can interpret from it earlier in the section detailing information with the SA_SIGINFO.)

And the sigtimedwait(2)? Well, it's quite apparent; it's identical to the sigwaitinfo(2) API, except that there is an additional parameter—a timeout value. Hence, the function will block the caller either until one of the signals in set is pending, or the timeout expires (whichever occurs first). The timeout is specified via a simple timespec structure, which allows one to provide the time in seconds and nanoseconds:

struct timespec {
long tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
}

If the structure is memset to zero, the sigtimedwait(2) returns immediately, either with information returned about a signal that was pending, or an error value. Both the sigwaitinfo(2) and the sigtimedwait(2) APIs return the actual signal number on success and -1 on failure, with errno set appropriately.

An important point to note (it has been mentioned previously, but it's key): neither the sigwaitsigwaitinfo, or sigtimedwait APIs can wait for synchronously generated signals from the kernel; typically the ones that indicate a failure of some sort, like the SIGFPE and the SIGSEGV. These can only be caught in the normal asynchronous fashion—via signal(2) or sigaction(2). For such cases, as we have repeatedly shown, the sigaction(2) system call would be the superior choice.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.5.151