如有转载,请注明出处:Windeal专栏
首先简述下几个概念的关系:
#include <signal.h> int sigemptyset(sigset_t *set); //清空信号集 int sigfillset(sigset_t *set); //填满信号集 int sigaddset(sigset_t *set,int signo); //添加一个信号 int sigdelset(sigset_t *set,int signo); //删除信号集中的一个信号 All four return: 0 if OK,?1 on error int sigismember(const sigset_t *set,int signo); Returns: 1 if true, 0 if false,?1 on error
#define sigemptyset(ptr) (*(ptr) = 0) #define sigfillset(ptr) (*(ptr) = ?(sigset_t)0, 0)
#include <signal.h> #include <errno.h> /* *<signal.h> usually defines NSIG to include signal number 0. */ #define SIGBAD(signo) ((signo) <= 0 || (signo) >= NSIG) int sigaddset(sigset_t *set, int signo) { if (SIGBAD(signo)) { errno = EINVAL; return(-1); } *set |= 1 << (signo - 1); /* turn bit on */ return(0); } int sigdelset(sigset_t *set, int signo) { if (SIGBAD(signo)) { errno = EINVAL; return(-1); } *set &= ?(1 << (signo - 1)); /* turn bit off */ return(0); } int sigismember(const sigset_t *set, int signo) { if (SIGBAD(signo)) { errno = EINVAL; return(-1); } return((*set & (1 << (signo - 1))) != 0); }
#include <signal.h> int sigprocmask(int how,const sigset_t *restrict set,sigset_t *restrict oset); Returns: 0 if OK,?1 on error
#include <signal.h> int sigpending(sigset_t *set); Returns: 0 if OK,?1 on error
$./a.out ?\ generate signal once (before5seconds areup) SIGQUIT pending after return fromsleep caught SIGQUIT in signal handler SIGQUIT unblocked after return fromsigprocmask ?\Quit(coredump) generate signal again $./a.out ?\?\?\?\?\?\?\?\?\?\ generate signal 10 times (before5seconds areup) SIGQUIT pending caught SIGQUIT signal is generated only once SIGQUIT unblocked ?\Quit(coredump) generate signal again
#include <signal.h> int sigsuspend(const sigset_t *sigmask); Returns:?1witherrnoset toEINTR
#include <signal.h>
int sigsuspend(const sigset_t *sigmask);
Returns:?1witherrnoset toEINTR
APUE学习笔记——10.11~10.13 信号集、信号屏蔽字、未决信号
原文地址:http://blog.csdn.net/windeal3203/article/details/39394981