EmbLogic's Blog

Using sigaction() as a replacement of signal().

Signal is a very important call to handle the behavior of any in coming signals as we know as default signal terminate the process but using signal() we can make the signal do according to need by running a function called signal handler. but what if another signal came during the execution of that signal handler than by default, the process get terminate(if the handler is not written for that signal) and if the same signal came ,the handler program restarts after completing itself. means it limited for multiple signals in a process. This problem overcame by sigaction() call. It also works as signal() but it has some extra features so that it can handle upcoming signal by placing in a queue when the execution of the first signal complete it take the next signal and run the definition. sigaction() is a kernel data structure. sigaction() can mask a signal during the execution of first signal. we can also have information about the signal that why and where it is coming from.
basic structure of sigaction is,
struct sigaction {
1 void (*sa_handler)(int);
2 void (*sa_sigaction)(int, siginfo_t *, void *);
3 sigset_t sa_mask;
4 int sa_flags;
5 void (*sa_restorer)(void);
};
1. first is the normal signal which contain signal number and handler.
2. it is the new handler which has signal number , signal info why and from where it is coming from, and user context to supply handler at run time.
3. signal mask is to mask another or upcoming signal.
4. sa_flag is equal to siginfo_t , it is used to run siginfo properly.

because sigaction has these extra option , it can be used enhanced signal purpose.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>