Thursday, 29 June 2017

Signals in Linux

A signal is a software interrupt delivered to notify a process or thread of a particular event.
The operating system uses signals to report exceptional situations to an executing program. Some signals report errors such as references to invalid memory addresses; others report asynchronous events.


The sigaction system call has the same basic effect as signal system call: to specify how a signal should be handled by the process. 

But sigaction offers more control over the signal mechanism, at the expense of more complexity.

#include

int sigaction(int signum, const struct sigaction *action,struct sigaction *oldaction);


The simplest way to change the action for a signal is to use the signal system call.
typedef void (*sighandler_t)(int);

sighandler_t signal(int signum, sighandler_t handler).



Temporary blocking of signals with sigprocmask gives you a way to prevent interrupts during critical parts of your code. If signals arrive in that part of the program, they are delivered later, after you unblock them.

Signals, such as SIGSTOP and SIGKILL, cannot be blocked. If an attempt is made to block these signals, the system ignores the request without reporting an error.
 

No comments:

Post a Comment