Signals are essentially software interrupts delivered to a process by the operating system or another process. When a signal is sent to a process, the process is interrupted, and control is transferred to the signal handler. The signal handler can perform a specific action in response, such as cleaning up resources, terminating the process, or ignoring the signal.
If the process doesn’t define a custom signal handler, the OS applies a default action, which could be to terminate the process or ignore the signal, depending on the signal type.
Common Signal Types
- SIGHUP (Signal Hangup): Sent to a process when its controlling terminal is closed. It’s often used to tell daemons to reload their configuration.
- SIGINT (Signal Interrupt): Sent to a process when the user interrupts it by pressing
Ctrl+C. Typically, this is used to terminate the process.
- SIGQUIT: Sent when the user presses
Ctrl+\\. It causes the process to terminate and create a core dump (for debugging).
- SIGKILL: A signal that forces the process to terminate immediately. This signal cannot be caught, blocked, or ignored by the process.
- SIGTERM: A polite request to terminate the process. The process can catch this signal and perform cleanup before exiting, but it can also ignore the signal.
- SIGSTOP and SIGCONT: These signals stop and continue a process, respectively. The process can't catch or ignore these signals.