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 a654bcc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ env:
jobs:
lint:
runs-on: ubuntu-latest
concurrency:
group: tests-${{ github.workflow }}-${{ github.event.number || github.ref }}
cancel-in-progress: true
permissions:
id-token: write
contents: read
Expand Down
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))
}
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 a654bcc

Please sign in to comment.