Adding the initial commit of the SigChan library.
Later additions will include the ability to set a custom callback upon receiving the interrupt signal.
This commit is contained in:
parent
e6591ca234
commit
9d8aa2c5b7
19
main.go
Normal file
19
main.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user