Signals are a way of inter-process communication (IPC) that works like an interrupt. To send a signal to a process, a program uses the system call kill(). A process receiving a signal suspends execution of its program immediately and executes a signal handler procedure instead. After that it resumes the program. A process can register a signal handler procedure for each individual signal type. If no signal handler has been registered for the issued signal, the default handling is to terminate the process.
A signal handler is a procedure which has to be registered for one or many signals and which is restricted in its capability to execute operating systems calls. Therefore a signal handler will either react to the signal directly or save necessary information about the signal, so that the main program can handle it at a later point. The Unix version of Apache uses a very simple signal handler (see figure 4.8 right-hand side) which just sets flags.
The process can also ignore every signal except SIGKILL which will always terminate the addressed process. Any signal which is ignored will simply be discarded. Another option is to block a signal, which is similar to ignoring the signal. The signal will then not be relayed to the process as if it was ignoring it. However any arriving signal is saved and will be forwarded to the process when the signal is unblocked. Using that feature a process can prevent a signal from interrupting its execution during important parts of the execution sequence. Blocking signals at the beginning of a signal handler and reenabling at the end of its execution is a good way to prevent race conditions of multiple signal handlers executing concurrently.
Additionally most UNIX flavours allow associating single signal handlers with a set of signals. Signal sets can be ignored or blocked as a whole set. When a signal handler is responsible for a set of signals, the parameter of the handling function will supply information about which signal triggered the handler.
However, signals are a technique that is very limited. Only a fixed range of signals exist. Apart from information that might be encoded in the choice of a specific signal type there is no possibility to send additional information to the addressed process. Furthermore the routines that handle signals are limited in their capabilities. Only a narrow range of system calls may be executed.
Signal handlers are registered for a specific signal type using the signal() system call. Signal() expects an integer for the signal type and a function pointer to the signal handling procedure. Generally a signal can be sent using the kill() system call. This function requires a process id and a signal type as arguments. On most UNIX systems there is also a command that can be used on the shell named kill. Users can use it to send signals to running processes. Unix versions of Apache can be restarted or shut down using the kill command.
A process can address signals to itself using the raise() call. Alarm() instructs the system to interrupt the process using the SIGALRM signal after a certain time, like an alarm clock. Therefore the alarm() system call only be used by a process to send a specific signal to itself.
Sets of signals can be managed easily by using so-called signal masks. A set of signals can be assigned to one single signal handler or a can be equally ignored or blocked by a process.
|Apache Modeling Portal