SIGPROCMASK(2) Linux Programmer's Manual SIGPROCMASK(2)
NAME
sigprocmask - examine and change blocked signals
功能 sigprocmask - 测试和改变被屏蔽的信:号
SYNOPSIS
头文件 #include
函数 int sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
参数:
how:
The behavior of the call is dependent on the value of how, as follows.
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
The set of blocked signals is set to the argument set.
*set:
If set is NULL, then the signal mask is unchanged (i.e., how is
ignored), but the current value of the signal mask is nevertheless
returned in oldset (if it is not NULL).
*oldset:
If oldset is non-NULL, the previous value of the signal mask is stored
in oldset.
返回值:成功返回0,失败返回-1
1 //屏蔽2号信号
2 #include
3 #include
4
5 int main(void){
6 sigset_t set,oset;
7 //将集合清空
8 sigemptyset(&set);
9 //将2信号添加到集合set里
10 sigaddset(&set,SIGINT);
11 sigprocmask(SIG_SETMASK,&set,&oset);
12 // sigprocmask(SIG_BLOCK,&set,&oset);
13 while(1);
14 return 0;
15 }
前台与后台之间转换过程
1)在shell下,启动一个前台进程。
2)用户按下crtl+c,这个键盘输入产生一个硬件中断
3)如果此时cpu正在运行进程的用户空间代码,
需要切换到内核空间,处理硬件中断。
4)中断驱动程序将crtl+c 解释成一个sigint信号,记
在该进程的PCB中。
5)从内核返回到用户空间的时候,先检查
进程的PCB中是否有信号到达。如果有信号到达,
调用信号处理函数。
6)处理完毕后,继续返回内核,再次判断是否有信号到达。
如有切换到第五步,没有,返回进程的用户态,继续执行。