-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include os specific termination signaling
Signed-off-by: Christian Kruse <[email protected]>
- Loading branch information
Showing
7 changed files
with
60 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package command | ||
|
||
import ( | ||
"os/exec" | ||
"syscall" | ||
) | ||
|
||
// setOptions sets the process group of the command processprocgroup | ||
func setOptions(cmd *exec.Cmd) { | ||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true, Pdeathsig: syscall.SIGTERM} | ||
cmd.Cancel = func() error { | ||
// Kill process group instead | ||
return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//go:build !linux && !windows | ||
// +build !linux,!windows | ||
|
||
package command | ||
|
||
import ( | ||
"os/exec" | ||
"syscall" | ||
) | ||
|
||
// setOptions sets the process group of the command process | ||
func setOptions(cmd *exec.Cmd) { | ||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} | ||
cmd.Cancel = func() error { | ||
// Kill process group instead | ||
return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"syscall" | ||
) | ||
|
||
// setOptions sets the process group of the command process | ||
func setOptions(cmd *exec.Cmd) { | ||
cmd.SysProcAttr = &syscall.SysProcAttr{ | ||
CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP, | ||
} | ||
cmd.Cancel = func() error { | ||
// Try with taskkill first | ||
taskkill := exec.Command( | ||
"taskkill", | ||
"/T", "/F", "/PID", fmt.Sprint(cmd.Process.Pid), | ||
) | ||
if err := taskkill.Run(); err == nil { | ||
return nil | ||
} | ||
// Fall back to the default behavior | ||
return cmd.Process.Kill() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.