//go:build windows package agentcmd import ( "os" "os/exec" "syscall" "golang.org/x/sys/windows" ) func detachProcess(cmd *exec.Cmd) { // CREATE_NEW_PROCESS_GROUP so stop can target the child; keep stdio so // stdout/stderr still reach the log file opened by the parent. cmd.SysProcAttr = &syscall.SysProcAttr{ CreationFlags: windows.CREATE_NEW_PROCESS_GROUP, } } func signalAlive(pid int) bool { // On Windows, FindProcess always succeeds; use OpenProcess exit code instead. h, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid)) if err != nil { return false } defer windows.CloseHandle(h) var code uint32 if err := windows.GetExitCodeProcess(h, &code); err != nil { return false } const stillActive = 259 // STILL_ACTIVE return code == stillActive } func signalTerminate(pid int) error { p, err := os.FindProcess(pid) if err != nil { return err } return p.Kill() } func signalKill(pid int) error { return signalTerminate(pid) }