platform agnostic kill process
parent
1cfa96ff09
commit
6889e8f42e
|
|
@ -18,8 +18,6 @@ package util
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -50,33 +48,26 @@ func Logf(str string, args ...interface{}) {
|
|||
|
||||
// KillProcess kills the process associated with the given pid and all its children
|
||||
func KillProcess(pid int, t *testing.T) error {
|
||||
if runtime.GOOS == "windows" {
|
||||
p, err := process.NewProcess(int32(pid))
|
||||
p, err := process.NewProcess(int32(pid))
|
||||
if err != nil {
|
||||
// Process doesn't exist
|
||||
return err
|
||||
}
|
||||
children, err := p.Children()
|
||||
if err != nil {
|
||||
// No children, log the error, don't exist
|
||||
t.Log(err)
|
||||
}
|
||||
for _, c := range children {
|
||||
err = c.Kill()
|
||||
if err != nil {
|
||||
// Process doesn't exist
|
||||
return err
|
||||
}
|
||||
children, err := p.Children()
|
||||
if err != nil {
|
||||
// No children, log the error, don't exist
|
||||
// Log the error, but don't exit
|
||||
t.Log(err)
|
||||
}
|
||||
for _, c := range children {
|
||||
err = c.Kill()
|
||||
if err != nil {
|
||||
// Log the error, but don't exit
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
err = p.Kill()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err := syscall.Kill(-pid, syscall.SIGKILL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err = p.Kill()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -146,9 +146,6 @@ func (m *MinikubeRunner) RunWithContext(ctx context.Context, cmdStr string, wait
|
|||
path, _ := filepath.Abs(m.BinaryPath)
|
||||
|
||||
cmd := exec.CommandContext(ctx, path, cmdArgs...)
|
||||
if runtime.GOOS != "windows" {
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
}
|
||||
Logf("RunWithContext: %s", cmd.Args)
|
||||
return m.teeRun(cmd, wait...)
|
||||
}
|
||||
|
|
@ -161,9 +158,6 @@ func (m *MinikubeRunner) RunDaemon(cmdStr string) (*exec.Cmd, *bufio.Reader) {
|
|||
path, _ := filepath.Abs(m.BinaryPath)
|
||||
|
||||
cmd := exec.Command(path, cmdArgs...)
|
||||
if runtime.GOOS != "windows" {
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
}
|
||||
stdoutPipe, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
m.T.Fatalf("stdout pipe failed: %s %v", cmdStr, err)
|
||||
|
|
@ -195,9 +189,6 @@ func (m *MinikubeRunner) RunDaemon2(cmdStr string) (*exec.Cmd, *bufio.Reader, *b
|
|||
cmdArgs := strings.Split(cmdStr, " ")
|
||||
path, _ := filepath.Abs(m.BinaryPath)
|
||||
cmd := exec.Command(path, cmdArgs...)
|
||||
if runtime.GOOS != "windows" {
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
}
|
||||
stdoutPipe, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
m.T.Fatalf("stdout pipe failed: %s %v", cmdStr, err)
|
||||
|
|
|
|||
Loading…
Reference in New Issue