Study and use of os/signal package in go language

Source: Internet
Author: User
Package Main;import ("OS" "Os/signal" "FMT")//signal packet provides two functions//NOTIFYF () for listening signals//stop () used to stop the Listener Func main ()  {ch: = Make (Chan os. Signal)//notify for the monitoring signal//parameter 1 for the received signal channel//parameter 2 and the subsequent signal//os to listen. Interrupt indicates interrupt//os. Kill kills the exit process signal. Notify (CH, os. Interrupt, OS. Kill);//Get the signal, if not it will always be blocked here. S: = <-ch;//We kill the process by CTRL + C or with taskkill/pid-t-F to see the effect. Fmt. PRINTLN ("Signal:", s);}

Package Main;import ("OS", "Os/signal" "FMT") func main () {ch: = make (chan os). Signal);//If you do not specify a signal to listen on, the default is all signal Signal. Notify (CH);//stop forwarding the signal to CH, CH will no longer receive any signal signal. Stop (CH);//ch will always be blocked here because it will not receive any signals//so the exit output below cannot perform <-ch;fmt. Println ("Exit");}

  

Study and use of os/signal package in go language

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.