Register a signal
==================
- Program can handle a signal using signal library function signal().
- signal() is used to register the signal handler function with kernel on behalf of current process.
- It is included in header :-
#include<header.h>
- Prototype of function is :-
void* (signal(int signo,void(*func)(int)))(int);
- signal() function takes 2 parameters, signo and func.
- The signal to be caught or ignored is given as argument signo.
- The function to be called when the specified signal is received is given as func.
- The function must take a single int argument (the signal received) and has return type void.
- The signal() command can be used in 3 modes :-
(i) Default mode (Terminate the process)
SIG_DFL –> is used in place of func.
(ii) Ignore the signal
SIG_IGN –> is used in place of func.
(iii) User defined mode
User defined function is used in place of func.
- The signal command returns the function which is setup to handle the signal, SIG_DFL or SIG_IGN in 3rd, 1st and 2nd cases respectively.