System Signal Processing in go

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.