package main
import (
"fmt"
"os"
"os/signal"
"time"
)
func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for sig := range c {
fmt.Printf("received ctrl+c(%v)\n", sig)
os.Exit(0)
}
}()
for {
time.Sleep(1000)
}
}
有疑问加站长微信联系(非本文作者)