-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtimeout_unix.go
More file actions
39 lines (33 loc) · 766 Bytes
/
timeout_unix.go
File metadata and controls
39 lines (33 loc) · 766 Bytes
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
31
32
33
34
35
36
37
38
39
// +build !windows
package timeout
import (
"os/exec"
"syscall"
)
func init() {
defaultSignal = syscall.SIGTERM
}
func (tio *Timeout) getCmd() *exec.Cmd {
if tio.Cmd.SysProcAttr == nil {
tio.Cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
}
return tio.Cmd
}
func (tio *Timeout) terminate() error {
sig := tio.signal()
syssig, ok := sig.(syscall.Signal)
if !ok || tio.Foreground {
return tio.Cmd.Process.Signal(sig)
}
err := syscall.Kill(-tio.Cmd.Process.Pid, syssig)
if err != nil {
return err
}
if syssig != syscall.SIGKILL && syssig != syscall.SIGCONT {
return syscall.Kill(-tio.Cmd.Process.Pid, syscall.SIGCONT)
}
return nil
}
func (tio *Timeout) killall() error {
return syscall.Kill(-tio.Cmd.Process.Pid, syscall.SIGKILL)
}