数据结构
[include/types/signal.h]
struct signal_descriptor {
int count; /* number of times raised */
void (*handler)(int sig);
};
struct signal_descriptor signal_state[MAX_SIGNAL];
int signal_queue_len; /* length of signal queue, <= MAX_SIGNAL (1 entry per signal max) */
int signal_queue[MAX_SIGNAL]; /* in-order queue of received signals */
sigset_t blocked_sig;
信号描述符包括两个成员,一个是信号触发次数;另一个是信号的实际处理函数。signal_state是一个信号描述符的数组。
信号安装
[src/signal.c]signal_register
void signal_register(int sig, void (*handler)(int))
{
if (sig < 0 || sig > MAX_SIGNAL) {
qfprintf(stderr, "Failed to register signal %d : out of range [0..%d].\n", sig, MAX_SIGNAL);
return;
}
signal_state[sig].count = 0;
if (handler == NULL)
handler = SIG_IGN;
if (handler != SIG_IGN &&