- 与信号集操作相关的函数
#include <signal.h>
清空信号集 全都为0
int sigemptyset(sigset_t *set);
填充信号集 全都为1
int sigfillset(sigset_t *set);
添加某个信号到信号集
int sigaddset(sigset_t *set, int signum);
从集合中删除某个信号
int sigdelset(sigset_t *set, int signum);
判断信号是否在信号集中
int sigismember(const sigset_t *set, int signum);
以上函数的返回值
sigemptyset(), sigfillset(), sigaddset(), and sigdelset() return 0 on
success and -1 on error.
sigismember() returns 1 if signum is a member of set, 0 if signum is
not a member, and -1 on error.
- 用来设置或者是解除阻塞信号的函数
#include <signal.h>
int sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
参数介绍:
how
SIG_BLOCK 设置阻塞
The set of blocked signals is the union of the current set and
the set argument.
SIG_UNBLOCK 解除阻塞
The signals in set are removed from the current set of blocked
signals. It is permissible to attempt to unblock a signal which
is not blocked.
SIG_SETMASK 设置set为新的阻塞信号集
The set of blocked signals is set to the argument set.
set 传入的信号集
oldset 传出的信号集
return:
sigprocmask() returns 0 on success and -1 on error.
- sigpending函数
读取当前进程的未决信号集
man sigpending
#include <signal.h>
int sigpending(sigset_t *set);
set为传出参数
返回值:成功0, 失败-1,设置errno
- 代码案例:
设置屏蔽信号集,然后发送信号,然后打印当前未决信号集
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
int main() {
sigset_t pend, setShield;
sigemptyset(&setShield);
sigaddset(&setShield, SIGINT);
sigaddset(&setShield, SIGQUIT);
sigprocmask(SIG_BLOCK, &setShield, NULL);
while (1) {
sigpending(&pend);
int i=1;
for(; i<32; ++i) {
printf("%d", sigismember(&pend, i));
}
printf("\n");
sleep(1);
}
return 0;
}
// 0110000000000000000000000000000