信号屏蔽
信号屏蔽(信号搁置)与忽略信号的区别
1.信号屏蔽并没有删除信号,只是将未处理的信号存入了搁置信号集,而忽略信号是将未处理的信号直接删除
信号屏蔽函数:
int sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
@how:
1.级联方式:
在原有基础上加减: 5 + 1 = 6, 6 - 1 = 5
SIG_BLOCK +信号,屏蔽
The set of blocked signals is the union of the current set and the set argument.
SIG_UNBLOCK -信号,解屏蔽
2.覆盖方式
SIG_SETMASK:覆盖方式, int a = 100; int olda = a; a = 200;
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
void sigfun(int args)
{
printf("%s %d start\n", __func__, __LINE__);
if (SIGINT == args)
printf("this signal is SIGINT\n"); //ctrl+c
else if (SIGQUIT == args)
printf("this signal is SIGQUIT\n"); //ctrl+/
printf("%s %d stop\n", __func__, __LINE__);
}
int main()
{