- 15
- 0
- 约2.29万字
- 约 86页
- 2019-01-05 发布于浙江
- 举报
* sigprocmask Function How to modify? (set != NULL, how = …) How Description SIG_BLOCK Union of current signal mask and signal mask SIG_UNBLOCK Intersection of current signal mask and signal mask SIG_SETMASK New signal mask * Program 10.10: print mask #include errno.h #include signal.h #include ourhdr.h void pr_mask(const char *str) { sigset_t sigset; int errno_save; errno_save = errno; /* we can be called by signal handlers */ if (sigprocmask(0, NULL, sigset) 0) err_sys(sigprocmask error); printf(%s, str); if (sigismember(sigset, SIGINT)) printf(SIGINT ); if (sigismember(sigset, SIGQUIT)) printf(SIGQUIT ); if (sigismember(sigset, SIGUSR1)) printf(SIGUSR1 ); if (sigismember(sigset, SIGALRM)) printf(SIGALRM ); /* remaining signals can go here */ printf(\n); errno = errno_save; } * sigpending Function sigpending returns the set of signals that are blocked and pending #include signal.h int sigpending(sigset_t *set); Returns: 0 if OK, -1 on error * Program 10.11: sigpending #include signal.h #include ourhdr.h static void sig_quit(int); int main(void) { sigset_t newmask, oldmask, pendmask; if (signal(SIGQUIT, sig_quit) == SIG_ERR) err_sys(cant catch SIGQUIT); sigemptyset(newmask); sigaddset(newmask, SIGQUIT); /* block SIGQUIT and save current signal mask */ if (sigprocmask(SIG_BLOCK, newmask, oldmask) 0) err_sys(SIG_BLOCK error); sleep(5); /* SIGQUIT here will remain pending */ if (sigpending(pendmask) 0) err_sys(sigpending error); * Program 10.11: sigpending if (sigismember(pendmask, SIGQUIT)) printf(\nSIGQUIT pending\n); /* reset signal mask which unblocks SIGQUIT */ if (sigprocmask(SIG_SETMASK, oldmask, NULL) 0) err_sys(SIG_SETMASK error); printf(SIGQUIT unblocked\n); sleep(5); /* SIGQUIT here will terminate with core file */ exit(0); } static void sig_quit(int signo) { printf(caught SIGQUIT\n); if (signal(SIGQUIT, SIG_DFL) == SIG_ERR) err_sys(cant reset SIGQUIT); return; } * Program 10.11: resu
原创力文档

文档评论(0)