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
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 Pdeadthsig in the syscall.SetProcAddr.
You can setup a signal handler for common signals like 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.
See: Panic in other goroutine not stopping child process
cmd := exec.Command("./long-process")
cmd.SysProcAttr = &syscall.SysProcAttr{
Pdeathsig: syscall.SIGTERM,
}