package mainimport "fmt"import "os"import "os/signal"import "syscall"func main() {go SignalProc()done := make(chan bool, 1)for {select {case <-done:break}}fmt.Println("exit")}func SignalProc() {sigs := make(chan os.Signal)signal.Notify(sigs, syscall.SIGINT, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGHUP, os.Interrupt)for {msg := <-sigsfmt.Println("Recevied signal:", msg)switch msg {default:fmt.Println("get sig=%v\n", msg)case syscall.SIGHUP:fmt.Println("get sighup\n")case syscall.SIGUSR1:fmt.Println("SIGUSR1 test")case syscall.SIGUSR2:fmt.Println("SIGUSR2 test")}}}
// Kill-usr1 10323 kill-usr2 10323 kill-N 2 10323 you can configure SIGUSR1 to reload sigusr2 and reload game base.
Capture Ctrl + C signals
signal.Notify(c, os.Interrupt)
Command: Kill-num processid (PID)
Letter Comment comment |
Numeric Value |
Meaning |
Hup |
1 |
Slave in the control or in the program |
Int |
2 |
INSERT command of zookeeper (same as Ctrl + C) |
Quit |
3 |
The Forward Command in zookeeper (same as Ctrl + \) |
Term |
15 |
Program stopping command |
Kill |
9 |
Program logging and stopping commands (brute force splitting) |
Cont |
18 |
Program re-activation command (stop (19) and then re-launch) |
Stop |
19 |
Program stop command (same as Ctrl + Z) |
Generally, if the system is shut down, the system will first send the limit of the term (15) to stop the process. If not, the system will send kill (9) to stop the program.
From: http://sugarmanman.blog.163.com/blog/static/8107908020136713147504/
System Signal Processing in go