Walk through the example program that blocks the SIGINT signal for 10 seconds and then unblocks it. Explain the steps involved in setting up the signal handler, blocking the signal, and handling it after unblocking.
Firstly, the signal handler is set to handle SIGINT.
The sigaction call sets up the signal handler for SIGINT.
SIGINT is blocked by using sigaddset(&mask,SIGINT) adds SIGINT to the signal set.
sigprocmask(SIG_BLOCK,&mask,&oldmask) blocks sigint and saves the current signal mask in oldmask.
Then in criticals section the program is on sleep for 10 seconds . During this period , pressing ctrl+C won't interrupt the program because SIGINT is blocked.
sigprocmask(SIG_SETMASK,&oldmask,NULL) restores the old signal mask, unblocking SIGINT.
Since we have used an infinite loop at the end, the program will keep printing the statement in loop, just when ctrl+c is pressed, it will print the statement in the signal handler section, which will print caught signal 2.