前往React并按下Ctrl + D。

huangapple go评论86阅读模式
英文:

Go to react to Ctrl + D

问题

我经常使用Ctrl + d来关闭正在运行的Go程序,无论是通过go run还是二进制文件运行的。我该如何让代码对这个意外输入ctrl + d做出反应呢?例如,我正在运行一个创建EC2容器的脚本,但我在运行时取消了程序。然后我希望这段代码能对这个ctrl + d做出反应,并在关闭之前终止EC2

请告诉我!谢谢!

英文:

I often use Ctrl + d to shut down Go programs that is being run by go run or in binary. How do I make the code to react to this unexpected input ctrl + d ? For example, I am running a script that creates EC2 containers but I cancel the program during run time. Then I want this code to react to this ctrl + d and terminate the EC2 before it is shut down.

Please let me know! Thanks!

答案1

得分: 2

使用Ctrl-C,进程会接收到一个KILL信号。

你可以使用os/signal来捕获它,详细的示例可以参考这个链接:

http://golang.org/pkg/os/signal/#pkg-examples

英文:

With Ctrl-C, the process receives a KILL signal.

You can catch it with os/signal, read the example for the detail:

http://golang.org/pkg/os/signal/#pkg-examples

huangapple
  • 本文由 发表于 2014年11月29日 11:28:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/27198560.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定