Skip to content

Commit 2eee3af

Browse files
committed
use process group pid on windows
1 parent 9fbfb55 commit 2eee3af

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

process/interrupt_windows.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
package process
44

5-
import "syscall"
5+
import (
6+
"os"
7+
"syscall"
8+
)
69

710
var (
811
kernel32 = syscall.NewLazyDLL("kernel32.dll")
@@ -13,6 +16,9 @@ var (
1316
// On Windows, this uses GenerateConsoleCtrlEvent with CTRL_BREAK_EVENT
1417
// because Go's p.Signal(os.Interrupt) is not implemented on Windows.
1518
func SendInterrupt() {
16-
// CTRL_BREAK_EVENT = 1
17-
procGenerateConsoleCtrlEvent.Call(1, 0)
19+
// Send CTRL_BREAK_EVENT to current process's process group
20+
// Using os.Getpid() targets only processes in our group (typically just us in production)
21+
// This avoids sending to all console processes (group 0) which would kill parent processes
22+
pid := os.Getpid()
23+
procGenerateConsoleCtrlEvent.Call(syscall.CTRL_BREAK_EVENT, uintptr(pid))
1824
}

0 commit comments

Comments
 (0)