今天阅读Nginx源码,在ngx_master_process_cycle()函数看到相关内容
初步介绍
很多信号量阻塞函数都是通过类似于信号量集来说明具体哪个信号变化,一般分为两步:第一步产生一个signal set;第二部,将signal set 作为参数传递到另一个函数(原文写的是library function)
结构体:sigset_t
定义在 signal.h
为了方便移植,使用库函数去初始化、改变、恢复它,不要直接对其进行操作
(1)初始化
两种方法:
a.sigemptyset () 分别设置自己所需要的
b.sigfillset () 全部设置,然后去掉自己不用的
注意这两个略有不同
使用自己不熟悉的signals是很不明智的
函数原型:int sigemptyset (sigset_t *set)
int sigfillset (sigset_t *set)
int sigaddset (sigset_t *set, int signum)、
顾名思义,就是讲signum赋值给set ,仅仅是修改signal set,不会去阻塞或者更改原先的阻塞状态
成功返回0,失败返回-1,
错误码:EINVAL 没有指定一个有效的信号
int sigdelset (sigset_t *set, int signum)
与sigaddset()刚好相反
int sigismember (const sigset_t *set, int signum)
检测signum 是不是一个signal set的成员
错误码:EINVAL 没有指定一个有效的信号
Function: int sigemptyset (sigset_t *set)
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
This function initializes the signal set set to exclude all of the defined signals. It always returns 0.
Function: int sigfillset (sigset_t *set)
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
This function initializes the signal set set to include all of the defined signals. Again, the return value is 0.
Function: int sigaddset (sigset_t *set, int signum)
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
This function adds the signal signum to the signal set set. All sigaddset does is modify set; it does not block or unblock any signals.
The return value is 0 on success and -1 on failure. The following errno error condition is defined for this function:
EINVAL
The signum argument doesn’t specify a valid signal.
Function: int sigdelset (sigset_t *set, int signum)
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
This function removes the signal signum from the signal set set. All sigdelset does is modify set; it does not block or unblock any si