platform agnostic kill process

pull/5285/head
Sharif Elgamal 2019-09-09 13:42:50 -07:00
parent 1cfa96ff09
commit 6889e8f42e
No known key found for this signature in database
GPG Key ID: 23CC0225BD9FD702
2 changed files with 17 additions and 35 deletions

View File

@ -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

View File

@ -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)