从APUE的书上看,不可靠信号会造成两种情况
1. signals could get lost
2. difficult for a process to turn off selected signals when executing critical regions of code.
但是我还是有点晕,我想弄明白几点
1. 不可靠信号的表现是什么样子的?
2. 为什么会有不可靠信号? 内核的原因? 应用程序的原因?
3. 如何避免不可靠信号?
下面这段话摘自 http://tldp.org/LDP/lpg/node138.html
10.2 Signal handling
Over the years, the definition and semantics of signals have been modified in various ways by different implementations of UNIX. Today, there are two major classes of symbols: unreliable and reliable. Unreliable signals are those for which the signal handler does not remain installed once called. 不可靠信号的定义 These ``one-shot'' signals must re-install the signal handler within the signal handler itself, if the program wishes the signal to remain installed. Because of this, there is a race condition in which the signal can arrive again before the handler is re-installed, which can cause the signal to either be lost or for the original behavior of the signal to be triggered (such as killing the process). Therefore, these signals are ``unreliable'' because the signal catching and handler re-installation operations are nonatomic.
上面这段话中不仅定义了什么是不可靠信号,更加说明了不可靠的原因 。
1. 因为信号处理函数必须重新安装,那就可能产生一段时间的竞争。这不是一个原子操作,故信号会丢失。
Under unreliable signal semantics, system calls are not restarted automatically when interrupted by a signal. Therefore, in order for a program to account for all cases, the program would need to check the value of errno after every system call, and reissue the system call if its value is EINTR.
Along similar lines, unreliable signal semantics don't provide an easy way to get an atomic pause operation (put the process to sleep until a signal arrives). Because of the unreliable nature of reinstalling signal handlers, there are cases in which a signal can arrive without the program realizing this.
第二个不可靠的原因
2. pause操作也不是原子的 。
有关于不可靠原因的分析可以参见APUE section 10.4 unreliable signals
Under reliable signal semantics, on the other hand, the signal handler remains installed when called, and the race condition for reinstallation is avoided. Also, certain system calls can be restarted, and an atomic pause operation is available via the POSIX sigsuspend function.
针对不可靠信号,可靠信号做了改进。
1. 不需要重新安装信号处理函数。
2. 提供了原子操作的等待函数sigsuspend。