问题描述
Start()
Start()
package main
import "os/exec"
func main() {
cmd := exec.Command("sh", "test.sh")
cmd.Start()
}
main() test.sh
推荐答案
^ C 不会发生代码>.您可以做的是拦截发送到您的过程的信号,这样您就可以干净地结束了.
The subprocess should continue to run after your process ends, as long as it ends cleanly, which won't happen if you hit ^C
.
What you can do is intercept the signals sent to your process so you can end cleanly.
sigchan := make(chan os.Signal, 1)
signal.Notify(sigchan,
syscall.SIGINT,
syscall.SIGKILL,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
s := <-sigchan
// do anything you need to end program cleanly
}()
这篇关于在golang中程序退出后如何保持子进程运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!