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. Fro
Take a step back. sigset_t
is a construct that represents multiple signals upon which some action is going to be take via some system call (e.g. sigaction
) but since the data structure representing sigset_t
is opaque there needs to be a reliable way to initialize it. Local variables in C aren't automatically initialized and you can't just assume sigset_t is an integer type and initialize it to zero because it might be a structure or some other unknown type. Thus sigemptyset
and sigfillset
are provided to reliably empty (turn all signals off) or fill (turn all signal on) the sigset_t
representation.
Your actual confusion may be what the signal sets inherent in sigset_t are used for and the answer to that is they are used for multiple things. You may want to block multiple signals in one call by passing a set to appropriate call. Or you may want to check all pending signals in one call. In short, it depends, but a set allows you to operate on multiple signals in one shot rather than a sequential series of actions - something which is particularly problematic with signals because they are asynchronous and subject to all kinds of race conditions.