Go provides the os/signal package to help developers to work with signals. This section will show you how to use it for UNIX signal handling.
First, let me present some useful information about UNIX signals. Have you ever pressed Ctrl+C in order to stop a running program? If your answer is "yes," then you are already familiar with signals because Ctrl+C sends the SIGINT signal to a program. Strictly speaking, UNIX signals are software interrupts that can be accessed either by name or by number, and they offer a way to handle asynchronous events on a UNIX system. Generally speaking, it is safer to send a signal by name because you are less likely to send the wrong signal accidentally.
A program cannot handle all of the available signals. Some signals cannot be caught, but nor can they be ignored. The SIGKILL and SIGSTOP signals cannot be caught,...