Skip to content

Commit 785a75a

Browse files
committed
platform-specific process killing
1 parent df82d57 commit 785a75a

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

cli/run.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,7 @@ Run 'dispatch help run' to learn about Dispatch sessions.`, BridgeSession)
205205
s = os.Kill
206206
}
207207
if cmd.Process != nil && cmd.Process.Pid > 0 {
208-
// Sending the signal to -pid sends it to all processes
209-
// in the process group.
210-
_ = syscall.Kill(-cmd.Process.Pid, s.(syscall.Signal))
208+
killProcess(cmd.Process, s.(syscall.Signal))
211209
}
212210
}
213211
}

cli/run_darwin.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
package cli
22

3-
import "syscall"
3+
import (
4+
"os"
5+
"syscall"
6+
)
47

58
func setSysProcAttr(attr *syscall.SysProcAttr) {
69
attr.Setpgid = true
710
}
11+
12+
func killProcess(process *os.Process, signal os.Signal) {
13+
// Sending the signal to -pid sends it to all processes
14+
// in the process group.
15+
_ = syscall.Kill(-process.Pid, signal.(syscall.Signal))
16+
}

cli/run_linux.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
package cli
22

3-
import "syscall"
3+
import (
4+
"os"
5+
"syscall"
6+
)
47

58
func setSysProcAttr(attr *syscall.SysProcAttr) {
69
attr.Setpgid = true
710
attr.Pdeathsig = syscall.SIGTERM
811
}
12+
13+
func killProcess(process *os.Process, signal os.Signal) {
14+
// Sending the signal to -pid sends it to all processes
15+
// in the process group.
16+
_ = syscall.Kill(-process.Pid, signal.(syscall.Signal))
17+
}

cli/run_windows.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package cli
2+
3+
import "os"
4+
5+
func killProcess(process *os.Process, _ os.Signal) {
6+
process.Kill()
7+
}

0 commit comments

Comments
 (0)