Prerequisite : Fork system call, Wait system call
A signal is a software generated interrupt that is sent to a process by the OS because of when user press ctrl-c or another process tell something to this process.
There are fix set of signals that can be sent to a process. signal are identified by integers.
Signal number have symbolic names. For example SIGCHLD is number of the signal sent to the parent process when child terminates.
Examples:
#define SIGHUP 1 /* Hangup the process */ #define SIGINT 2 /* Interrupt the process */ #define SIGQUIT 3 /* Quit the process */ #define SIGILL 4 /* Illegal instruction. */ #define SIGTRAP 5 /* Trace trap. */ #define SIGABRT 6 /* Abort. */
OS Structures for Signals
A signal is sent to a process setting the corresponding bit in the pending signals integer for the process. Each time the OS selects a process to be run on a processor, the pending and blocked integers are checked. If no signals are pending, the process is restarted normally and continues executing at its next instruction.
If 1 or more signals are pending, but each one is blocked, the process is also restarted normally but with the signals still marked as pending. If 1 or more signals are pending and NOT blocked, the OS executes the routines in the process’s code to handle the signals.
Default Signal Handlers
There are several default signal handler routines. Each signal is associated with one of these default handler routine. The different default handler routines typically have one of the following actions: