Unix signals are software interrupts that are sent to a program to indicate that some important event has occurred. The events can vary from user requests to illegal memory access errors. Some signals, such as the interrupt signal, indicate that a user has asked the program to do something, not in the usual control flow.
Dealing with the operating system signals is important for various use cases in applications. For example, we might want a server to gracefully shut down when it receives a SIGTERM, or a command-line tool to stop processing input if it receives a SIGINT. Here’s how to handle signals in Go with channels.
Golang’s os/signal the package allows you to configure the behavior of your Golang program upon receiving certain types of UNIX signals. Most Linux/Unix-based programs will gladly die upon receiving a kill signal, but in case you want your program to intercept the signal first, perform some backup, flush data to disk, etc before dying,