2 * 10.11: Demonstrates the use of sigpending() and sigismember()
3 * by installing a handler for SIGQUIT, blocking it and checking
11 static void sig_quit(int signo
)
13 fprintf(stderr
, "caught SIGQUIT\n");
15 if (signal(SIGQUIT
, SIG_DFL
) == SIG_ERR
) {
16 fprintf(stderr
, "can't reset SIGQUIT\n");
23 sigset_t newmask
, oldmask
, pendmask
;
25 /* Installs sig_quit() as our handler for SIGQUIT */
26 if (signal(SIGQUIT
, sig_quit
) == SIG_ERR
) {
27 fprintf(stderr
, "can't catch SIGQUIT\n");
32 sigemptyset(&newmask
);
33 sigaddset(&newmask
, SIGQUIT
);
35 if (sigprocmask(SIG_BLOCK
, &newmask
, &oldmask
) < 0) {
36 fprintf(stderr
, "SIG_BLOCK error\n");
41 * Sleeps for five seconds. In this period we should
42 * receive a SIGQUIT, but as it's blocked we continue
47 if (sigpending(&pendmask
) < 0) {
48 fprintf(stderr
, "sigpending error\n");
52 if (sigismember(&pendmask
, SIGQUIT
))
53 printf("SIGQUIT pending\n");
55 if (sigprocmask(SIG_SETMASK
, &oldmask
, NULL
) < 0) {
56 fprintf(stderr
, "SIG_SETMASK error\n");
59 printf("SIGQUIT unblocked\n");