Skip to content

Commit

Permalink
platform-specific process killing
Browse files Browse the repository at this point in the history
  • Loading branch information
chicoxyzzy committed Jun 18, 2024
1 parent df82d57 commit 179fec9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
4 changes: 1 addition & 3 deletions cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ Run 'dispatch help run' to learn about Dispatch sessions.`, BridgeSession)
s = os.Kill
}
if cmd.Process != nil && cmd.Process.Pid > 0 {
// Sending the signal to -pid sends it to all processes
// in the process group.
_ = syscall.Kill(-cmd.Process.Pid, s.(syscall.Signal))
killProcess(cmd.Process, s.(syscall.Signal))
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion cli/run_darwin.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package cli

import "syscall"
import (
"os"
"syscall"
)

func setSysProcAttr(attr *syscall.SysProcAttr) {
attr.Setpgid = true
}

func killProcess(process *os.Process, signal os.Signal) {
// Sending the signal to -pid sends it to all processes
// in the process group.
syscall.Kill(-process.Pid, signal.(syscall.Signal))
}
11 changes: 10 additions & 1 deletion cli/run_linux.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package cli

import "syscall"
import (
"os"
"syscall"
)

func setSysProcAttr(attr *syscall.SysProcAttr) {
attr.Setpgid = true
attr.Pdeathsig = syscall.SIGTERM
}

func killProcess(process *os.Process, signal os.Signal) {
// Sending the signal to -pid sends it to all processes
// in the process group.
syscall.Kill(-process.Pid, signal.(syscall.Signal))

Check failure on line 16 in cli/run_linux.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `syscall.Kill` is not checked (errcheck)
}
7 changes: 7 additions & 0 deletions cli/run_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package cli

import "os"

func killProcess(process *os.Process, _ os.Signal) {
process.Kill()
}

0 comments on commit 179fec9

Please sign in to comment.