Unit content
Signal handling and graceful shutdown
A process can install a signal handler for many Unix signals so that delivery runs application-defined handling logic instead of the default action.
Graceful termination
Long-running programs commonly treat SIGTERM or SIGINT as a request to begin an orderly shutdown:
receive termination signal
↓
stop accepting new work
↓
finish or cancel active work
↓
flush persistent state
↓
exit
This is safer than relying on forced termination for normal service lifecycle management.
Handler restrictions
A signal can interrupt the program at an arbitrary point, so traditional low-level signal handlers must avoid operations that are not safe under asynchronous interruption.
A common design is to have the handler perform the smallest possible action—such as setting an atomic flag or notifying an event loop—and let ordinary program flow perform the complex cleanup.
Masking and pending signals
Processes can temporarily block selected signals while sensitive operations occur. A blocked signal can remain pending until delivery is permitted again.
Uncatchable signals
SIGKILL and SIGSTOP cannot be handled, blocked or ignored. They provide the operating system with mechanisms that the target process cannot override.