Reliable Signal VS Unreliable Signal

从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。

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值