package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func working() {
fmt.Printf("working....\n")
}
func main() {
sigs := make(chan os.Signal, 1)
done := make(chan bool, 1)
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)
go func() {
<-sigs
done <- true
}()
go working()
<-done
fmt.Printf("exist\n")
}
golang优雅的后台运行
最新推荐文章于 2024-01-31 17:55:26 发布