blob: 59c8c9a3db2b98f30fbaf7a698eab1a12dac3078 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package command
import (
"os/exec"
"syscall"
)
func ExitStatus(err error) (int, bool) {
if v, ok := err.(interface{ ExitCode() int }); ok {
return v.ExitCode(), true
} else if err != nil {
return -1, false
} else {
return 0, false
}
}
func KillProcessGroup(cmd *exec.Cmd) {
if cmd == nil {
return
}
if p := cmd.Process; p != nil && p.Pid > 0 {
// Send SIGTERM to the process group of cmd
syscall.Kill(-p.Pid, syscall.SIGTERM)
}
// reap our child process
cmd.Wait()
}
|