I have this code, and i have to make the program block repeatedly waiting for a signal. My teacher wants us to use the sigsuspend and masks instead of pause or sleep. I\'m not f
The simple way to get started is to just call sigsuspend
with an empty mask (i.e., any signal can wake up the program):
sigset_t myset;
(void) sigemptyset(&myset);
while (1) {
(void) printf("I'm running, waiting for a signal...\n");
(void) sigsuspend(&myset);
}
The next step would be to use sigprocmask
to disable your two handled signals (SIGINT
and SIGQUIT
) from occurring other than when you're waiting from them in sigsuspend
. Then you would use the “old mask” obtained from sigprocmask
instead of the empty mask when suspending.