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
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
.