任何人都可以用一种非常简单的方式解释一下sigemptyset()的作用吗?为什么有用?我读过很多定义,但我只是不明白.从我收集到的信息中,它跟踪用于阻塞目的的信号?我不太确定我是否理解为什么这样做会有用.是不是这样我们就不能递归地得到那个特定的信号?
Could anyone please explain in a really easy way to understand what sigemptyset() does? Why is it useful? I've read a bunch of definitions but i just don't understand. From what i gather it tracks the signals that are being used for blocking purposes? I'm not really sure i understand why that would be useful. Is it so we do not get that specific signal recursively?
使用sigemptyset()的基本示例:
Basic example where sigemptyset() is used:
#include <signal.h> #include <stdio.h> #include <unistd.h> int main(){ struct sigaction act; sigemptyset(&act.sa_mask); act.sa_handler=function_name; act.sa_flags=0; sigaction(SIGINT, &act, 0); }推荐答案
sigemptyset只是将signalmask初始化为空,从而确保不会屏蔽任何信号. (也就是说,将接收所有信号)基本上,它与memset(0)相似,但是您不必知道实现的详细信息.因此,如果更改sa_mask成员,则无需调整代码,因为sigemptyset将处理该代码.
sigemptyset simply initializes the signalmask to empty, such that it is guaranteed that no signal would be masked. (that is, all signals will be received) Basically it is similar to a memset(0) but you don't have to know the details of the implementation. So if the sa_mask member is changed you don't need to adjust your code because it will be taken care of by sigemptyset.
更多推荐
信号处理和sigemptyset()
发布评论