sigaction 系统调用:如果 sa_mask 包含被阻止的信号之一怎么办?
struct sigaction
的 sa_mask
字段指定在处理程序调用期间被阻止的信号。这些信号在调用处理程序之前添加到进程块掩码中,并在处理程序完成后立即删除。如果sa_mask
和过程信号掩码重叠怎么办?那些被 sa_mask
和进程信号掩码屏蔽的信号是否会从进程信号掩码中删除?
The sa_mask
field of struct sigaction
specifies signals that are blocked during handler invocation. Those signals are added to the process block mask just before the handler is invoked and removed right after handler completion. What if sa_mask
and the process signal mask overlap? Will those signals that are masked both by sa_mask
and the process signal mask be removed from the process signal mask?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当信号处理程序返回时,在处理信号之前有效的信号掩码将作为返回过程的一部分自动恢复。除非您使用
longjmp
或siglongjmp
跳出信号处理程序,否则就会发生这种情况,在这种情况下,由您决定是否要手动保存和恢复信号掩码。有趣的是,如果您使用 SA_SIGINFO 标志来设置三参数形式的信号处理程序,则第三个参数指向的 ucontext_t 包含一个 sigset_t uc_sigmask 成员反映了保存的信号掩码。此外,我不确定这种用法是否受到 POSIX 的认可,但在我知道的所有现实系统上,您实际上可以在从信号处理程序返回之前修改 uc_sigmask 来设置不同的信号掩码(而不是恢复原始的)当信号处理程序返回时。例如,如果您想重新发出刚刚处理的信号,但在返回时使其保持阻塞,则可以使用此功能,以便稍后当信号再次被中断的代码解除阻塞或
时,它实际上会得到处理sigwaitinfo
或类似的被调用。When a signal handler returns, the signal mask that was in effect before the signal was handled gets restored atomically as part of the return process. This will happen unless you jump out of the signal handler with
longjmp
orsiglongjmp
, in which case it's up to you whether you want to manually save and restore the signal mask.As an interesting aside, if you use the
SA_SIGINFO
flag to setup a three-argument-form signal handler, theucontext_t
pointed to by the third argument contains asigset_t uc_sigmask
member reflecting the saved signal mask. Further, I'm not sure whether this usage is sanctioned by POSIX, but on all real-world systems I know of, you can actually modifyuc_sigmask
before returning from the signal handler to set a different signal mask (as opposed to restoring the original one) when the signal handler returns. This can be used, for example, if you want to re-raise the signal you just handled but leave it blocked when returning, so that it actually gets handled later on when the signal is again unblocked by the interrupted code or whensigwaitinfo
or similar is called.否。恢复原始信号掩码,即。之前被阻止的内容之后也会被阻止。
No. The original signal mask is restored, ie. what was blocked before would be blocked after.