Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signal handling and sigemptyset()

Tags:

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);  } 
like image 474
user2644819 Avatar asked Dec 19 '13 14:12

user2644819


People also ask

What Sigemptyset () will do?

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.

What is Sigset_t?

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.

What is Sigaction in C?

The sigaction() function allows the calling process to examine and/or specify the action to be associated with a specific signal.

What is a signal mask?

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.


1 Answers

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.

like image 148
Devolus Avatar answered Sep 28 '22 10:09

Devolus