SIGNAL
Signal is an event generated by the UNIX and linux system in response to some condition. Signals are raised by some error conditions,such as memory violations, floating point processor error, or illegal instruction. They are generated by the shell or terminal handler to cause interrupts and can also be explicitly sent from one process to another as a way of passing information or modifying behaviour.
Signal names are defined in headers file signal.h. eg.SIGABORT(Process abort),SIGALRM(Alarm clock),SIGKILL(Kill can’t be caught or ignored) etc.
We can check the signals by : kill -l
Usage for signal call:
void (*signal(int sig, void (*func)(int)))(int);
signal has to parameters sig and func . Signal to be caught or ignored is mentioned in argument sig.function to be called when a specified signal is received is given by func
SENDING SIGNALS TO ANOTHER PROCESS:
A process may send signal to another process, including itself by using kill. The kill command will fail if the program doesn’t have permission to send signal, often because target process is owned by another user.
Usage for kill call:
#include<sys/types.h>
#include<signal.h>
int kill(pid_t pid, int sig);
ROBUST SIGNAL INTERFACE:
Sigaction function : is used to setup the default signal (eg SIGINT ) to our user defined function ie. to update the properties of SIGINT (CTRL+C) to an user defined function .
Usage of Sigaction :
int signaction(int sig, const struct sigaction *act,struct sigaction *oact) ;
The sigaction structure, used to define action to be taken on receipt of specified by sig.If Sigaction returns 0 is successful and -1 if not.
Within sigaction structure pointed to by argument act, sa_handler is pointed to a function called when signal sig is received .
The sa_mask field specifies a set of signals to be added to the process’s signal mask before the sa_handler is called.
Signals caught by set of sigaction are by default not reset .