the code is as follows:
< H1 > include "apue.h" < / H1 >static void sig_int (int);
int
main (void)
{
sigset_t newmask, oldmask;
pr_mask("program start: ");
if (signal(SIGINT, sig_int) == SIG_ERR)
err_sys("signal(SIGINT) error");
sigemptyset(&newmask);
sigaddset(&newmask, SIGINT);
/*
* Block SIGINT and save current signal mask.
*/
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
err_sys("SIG_BLOCK error");
/*
* Critical region of code.
*/
pr_mask("in critical region: ");
/*
* Reset signal mask which unblocks SIGINT.
*/
if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
err_sys("SIG_SETMASK error");
pr_mask("after SIG_SETMASK: ");
pause();
/*
* And continue processing ...
*/
pr_mask("program exit: ");
exit(0);
}
static void sig_int (int signo)
{
pr_mask("\nin sig_int: ");
}
the book says:
SIGINTpausepause
but I compile and run according to the above code, and press the ctrl+c, signal between the following two sentences to catch
.pr_mask("after SIG_SETMASK: ");
pause();
I don"t know how the situation in the book will happen.