Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我经常Ctrl + d用来关闭正在运行go run或以二进制形式运行的 Go 程序。如何使代码对这种意外输入做出反应ctrl + d?例如,我正在运行一个创建EC2容器的脚本,但我在运行时取消了该程序。然后我希望这段代码对此做出反应并在它关闭之前ctrl + d终止它。EC2
Ctrl + d
go run
ctrl + d
EC2
请告诉我!谢谢!
使用 Ctrl-C,进程会收到一个 KILL 信号。
您可以使用 os/signal 捕获它,详细阅读示例:
http://golang.org/pkg/os/signal/#pkg-examples