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?
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() is part of a family of functions that manipulate signal sets. Signal sets are data objects that let a process keep track of groups of signals. For example, a process can create one signal set to record which signals it is blocking, and another signal set to record which signals are pending.
The sigset_t data type is used to represent a signal set. Internally, it may be implemented as either an integer or structure type. For portability, use only the functions described in this section to initialize, change, and retrieve information from sigset_t objects—don't try to manipulate them directly.
The sigaction() function allows the calling process to examine and/or specify the action to be associated with a specific signal.
The signal mask is the set of signals whose delivery is currently blocked for the caller (see also signal(7) for more details). The behavior of the call is dependent on the value of how, as follows. SIG_BLOCK The set of blocked signals is the union of the current set and the set argument.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With