当我遇到此代码和注释时,我正在阅读有关 pselect 系统调用的使用...
static void handler(int sig) { /* do nothing */ }
int main(int argc, char *argv[])
{
fd_set readfds;
struct sigaction sa;
int nfds, ready;
sa.sa_handler = handler; /* Establish signal handler */
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGINT, &sa, NULL);
/* ... */
ready = select(nfds, &readfds, NULL, NULL, NULL);
/* ... */
}
this solution suffers from a race condition: if the SIGINT signal is delivered after
the call to sigaction(), but before the call to select(), it will fail to interrupt
that select() call and will thus be lost.
现在我不确定sigaction 系统调用...最初我认为它有点保存与信号相对应的处理程序,就是这样...当信号到达时,它会查找它的处理程序并执行处理程序...但是如果那样的话是正确的,那么对应于信号的处理程序将为整个程序保存,并且每当信号到达时都会执行它......所以无论sigaction和select之间的持续时间多么短,都会处理信号......
但是这段代码看起来好像只有当它与 sigaction 的调用/执行一致时才处理信号......在调用完成后,信号将不会由 sigaction 为程序的其余部分设置的处理程序处理(我知道,听起来很荒谬)
请解释!!