|
The sigpending function returns the set of signals that are blocked from delivery and currently pending for the calling process.
就是說,返回的信號,是被已經(jīng)產(chǎn)生,但因為被block而沒有deliver的。
#include <stdio.h>
#include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include <errno.h> #include <unistd.h> #include <stdlib.h> #include <sys/wait.h> #include <errno.h> #include <unistd.h> static void sig_quit(int);
int
main(void) { sigset_t newmask, oldmask, pendmask; if (signal(SIGQUIT, sig_quit) == SIG_ERR)
perror("can't catch SIGQUIT"); /*
* Block SIGQUIT and save current signal mask. */ sigemptyset(&newmask); sigaddset(&newmask, SIGQUIT); if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) perror("SIG_BLOCK error"); sleep(5); /* SIGQUIT here will remain pending */
if (sigpending(&pendmask) < 0) perror("sigpending error"); if (sigismember(&pendmask, SIGQUIT)) printf("\nSIGQUIT pending\n"); /*
* Reset signal mask which unblocks SIGQUIT. */ if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) perror("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) perror("can't reset SIGQUIT"); } |
|
|
來自: 杰出天下 > 《linux系統(tǒng)編程》