github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zutil/daemon/signal_notwin.go (about) 1 //go:build !windows 2 // +build !windows 3 4 package daemon 5 6 import ( 7 "os" 8 "os/signal" 9 "syscall" 10 ) 11 12 func KillSignal() bool { 13 sig, stop := SignalChan() 14 s := <-sig 15 stop() 16 return s != syscall.SIGUSR2 17 } 18 19 func SignalChan() (<-chan os.Signal, func()) { 20 quit := make(chan os.Signal, 1) 21 signal.Notify(quit, os.Interrupt, os.Kill, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL, syscall.SIGUSR2) 22 return quit, func() { 23 signal.Stop(quit) 24 } 25 }