From ead1c478d70b5b3d85eff82749ea63c000c301c0 Mon Sep 17 00:00:00 2001 From: Clinton Collins Date: Sat, 24 Apr 2021 13:36:01 -0500 Subject: [PATCH] Add Windows SysProcAttr create new process group When programs on Windows are terminated the child processes will not be killed anymore. --- cmd_windows.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd_windows.go b/cmd_windows.go index 75fe0e1..6056cf2 100644 --- a/cmd_windows.go +++ b/cmd_windows.go @@ -16,5 +16,8 @@ func terminateProcess(pid int) error { } func setProcessGroupID(cmd *exec.Cmd) { - cmd.SysProcAttr = &syscall.SysProcAttr{} + // Set create new process group so the cmd and all its children become a new + // process group. This allows Stop to SIGTERM the cmd's process group + // without killing this process (i.e. this code here). + cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP} }