Many Unix programs accept signals like USR1
and USR2
. For example, to upgrade the executable for Nginx on the fly, you send kill -USR2
.
I understand that USR1
is a "user defined" signal, meaning that whoever created the program can use it to mean "shut down" or "dump your logs" or "print foo a thousand times" or whatever. But I don't understand why they must use this arbitrary name. Why not kill -UPGRADE
, or kill -GRACEFUL_SHUTDOWN
? Does Unix only allow specific signals?
While we're at it, Nginx also uses the following signals (see documentation):
HUP? WINCH? What's the reason for these names? Where can I learn more about this?
The signals available on an OS are defined by the OS (usually following POSIX) - they're not "strings" but rather integer constants with standard names. USR1
and USR2
are the two signals that have no attached specific meaning - intended for whatever arbitrary use the developer wants.
On your linux machine, read man 7 signal
for an overview of signal handling and signals.
You can redefine the meaning of other signals if you're prepared to deal with the OS issuing those signals in response to events. You can e.g. make HUP
mean "reload configuration" - as long as you're either certain that the process will never get a hangup (terminal loss), or you're prepared to handle cases where the OS and not a user sends the HUP signal.