File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ //go:build !windows
2+
3+ package process
4+
5+ import "os"
6+
7+ // SendInterrupt sends an interrupt signal to the current process.
8+ // On Unix systems, this sends os.Interrupt (SIGINT).
9+ func SendInterrupt () {
10+ if p , err := os .FindProcess (os .Getpid ()); err == nil {
11+ _ = p .Signal (os .Interrupt )
12+ }
13+ }
Original file line number Diff line number Diff line change 1+ //go:build windows
2+
3+ package process
4+
5+ import "syscall"
6+
7+ var (
8+ kernel32 = syscall .NewLazyDLL ("kernel32.dll" )
9+ procGenerateConsoleCtrlEvent = kernel32 .NewProc ("GenerateConsoleCtrlEvent" )
10+ )
11+
12+ // SendInterrupt sends an interrupt signal to the current process.
13+ // On Windows, this uses GenerateConsoleCtrlEvent with CTRL_BREAK_EVENT
14+ // because Go's p.Signal(os.Interrupt) is not implemented on Windows.
15+ func SendInterrupt () {
16+ // CTRL_BREAK_EVENT = 1
17+ procGenerateConsoleCtrlEvent .Call (1 , 0 )
18+ }
You can’t perform that action at this time.
0 commit comments