go_sigchan/main.go
Snoosaphone 9d8aa2c5b7 Adding the initial commit of the SigChan library.
Later additions will include the ability to set a custom callback upon
receiving the interrupt signal.
2019-12-28 01:13:45 -06:00

20 lines
332 B
Go

package sigchan
import (
"fmt"
"log"
"os"
"os/signal"
)
// SigChan listens for os interrupt signals and gracefully exits the program.
func SigChan() {
sigchan := make(chan os.Signal, 10)
signal.Notify(sigchan, os.Interrupt)
<-sigchan
fmt.Println()
log.Println("Received CTRL+C interrupt. Program killed!")
os.Exit(0)
}