When an operator runs:
the operating system does not immediately call the server's cleanup function. It sends a small asynchronous notification named SIGTERM.
The notification can arrive while the server is parsing a request, modifying a data structure, waiting for input, or executing inside a library. The server must decide what SIGTERM means and handle it without corrupting its own state.
This notification mechanism is called a signal.
A signal tells a process or thread that an event has occurred. It can interrupt the normal flow of execution, invoke a handler, or trigger a predefined operating-system action.
Signals support termination requests, terminal interaction, child-process notifications, timers, fault reporting, and application-defined events. Their compact interface is powerful, but their asynchronous nature requires care.
This chapter follows the signal lifecycle, explains dispositions, handlers, masks, pending signals, and interrupted system calls, and develops safe patterns for single-threaded and multithreaded programs.