2 * An example of signal usage
9 volatile sig_atomic_t quitflag
; /* set by the handler */
11 static void sig_int(int signo
)
14 printf("interrupt\n");
15 else if (signo
== SIGQUIT
)
21 sigset_t newmask
, oldmask
, zeromask
;
23 if (signal(SIGINT
, sig_int
) == SIG_ERR
) {
24 perror("signal(SIGINT)");
28 if (signal(SIGQUIT
, sig_int
) == SIG_ERR
) {
29 perror("signal(SIGQUIT)");
33 sigemptyset(&zeromask
);
34 sigemptyset(&newmask
);
35 sigaddset(&newmask
, SIGQUIT
);
38 * Block SIGQUIT and save current signal mask
40 if (sigprocmask(SIG_BLOCK
, &newmask
, &oldmask
) < 0) {
41 perror("sigprocmask()");
46 sigsuspend(&zeromask
);
49 * SIGQUIT has been caught and is now blocked; do whatever
51 printf("SIGQUIT caught!\n");
54 * Reset signal mask which unblocks SIGQUIT
56 if (sigprocmask(SIG_SETMASK
, &oldmask
, NULL
) < 0) {
57 perror("sigprocmask()");