确保Process处理被终止时,确保Go Process中调用的可执行文件被杀死 [英] Ensure executables called in Go Process get killed when Process is killed
问题描述
我有一些Go(golang)中的代码,它有几个不同的线程运行单独的可执行文件。我想确保如果用户在Go中杀死了我的进程,那么我有一种杀死我调用的可执行文件的方法,有没有办法做到这一点?
确保子进程被终止的唯一方法是在同一个进程组中启动它,并将进程组作为一个整体终止,或将 您可以为常见信号设置信号处理程序,如 I have some code that in Go (golang), has a few different threads running a separate executable. I want to ensure that if a user kills my process in Go, that I have a way of killing the executables I've called, is there a way to do that? The only ways to ensure that the child process is killed, is to start it in the same process group, and kill the process group as a whole, or set You can setup a signal handler for common signals like See: Panic in other goroutine not stopping child process
这篇关于确保Process处理被终止时,确保Go Process中调用的可执行文件被杀死的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! Pdeadthsig
在 syscall.SetProcAddr $ c
SIG_INT
和 SIG_TERM
,并且在退出之前终止你的子进程,但是因为你不能捕获 SIG_KILL
,这通常是不值得的。 / p>
cmd:= exec.Command(./罗ng-process)
cmd.SysProcAttr =& syscall.SysProcAttr {
Pdeathsig:syscall.SIGTERM,
}
Pdeadthsig
in the syscall.SetProcAddr
.SIG_INT
and SIG_TERM
, and kill your child processes before exiting, but since you can't catch SIG_KILL
that's often not worth the effort.cmd := exec.Command("./long-process")
cmd.SysProcAttr = &syscall.SysProcAttr{
Pdeathsig: syscall.SIGTERM,
}