Handling UNIX signals
UNIX signals offer a very handy way of interacting asynchronously with applications and server processes. UNIX signal handling in Go requires the use of channels that are used exclusively for this task. The presented program handles SIGINT
(which is called syscall.SIGINT
in Go) and SIGINFO
separately and uses a default
case in a switch
block for handling the remaining signals. The implementation of that switch
block allows you to differentiate between the various signals according to your needs.
There exists a dedicated channel that receives all signals, as defined by the signal.Notify()
function. Go channels can have a capacity—the capacity of this particular channel is 1 in order to be able to receive and keep one signal at a time. This makes perfect sense as a signal can terminate a program and there is no need to try to handle another signal at the same time. There is usually an anonymous function that is executed as a goroutine and performs the...