简体   繁体   English

sa_mask 默认值为空吗?

[英]Is sa_mask default value empty?

I'm trying to implement a signal handler and was wondering if I need to explicitly empty sa_mask field of the struct sigaction or if by initializing it with default value is sufficient.我正在尝试实现一个信号处理程序,并且想知道是否需要显式清空struct sigactionsa_mask字段,或者是否使用默认值对其进行初始化就足够了。

Practically, you can initialize the structure to 0 with something like memset() and then initialize the signal handler field:实际上,您可以使用memset()之类的方法将结构初始化为 0,然后初始化信号处理程序字段:

struct sigaction action;

memset(&action, 0, sizeof(struct sigaction));
action.sa_handler = handler_func;

Theoretically, a typed object like "sigset_t" comes with its proper initialization method.从理论上讲,像“sigset_t”这样的类型化 object 带有其正确的初始化方法。 And so, you can't suppose that setting it to 0 through memset() will work.因此,您不能认为通过memset()将其设置为 0 会起作用。 Hence, for this field, you are supposed to use the signal set related routines to manipulate it:因此,对于该字段,您应该使用信号集相关例程来操作它:

struct sigaction action;

memset(&action, 0, sizeof(struct sigaction));
sigemptyset(&(action.sa_mask));
action.sa_handler = handler_func;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM