forked from air-verse/air
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_linux.go
35 lines (28 loc) · 823 Bytes
/
util_linux.go
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
package runner
import (
"io"
"os/exec"
"syscall"
"time"
"github.com/creack/pty"
)
func (e *Engine) killCmd(cmd *exec.Cmd) (pid int, err error) {
pid = cmd.Process.Pid
if e.config.Build.SendInterrupt {
// Sending a signal to make it clear to the process that it is time to turn off
if err = syscall.Kill(-pid, syscall.SIGINT); err != nil {
return
}
time.Sleep(e.config.Build.KillDelay)
}
// https://stackoverflow.com/questions/22470193/why-wont-go-kill-a-child-process-correctly
err = syscall.Kill(-pid, syscall.SIGKILL)
// Wait releases any resources associated with the Process.
_, _ = cmd.Process.Wait()
return
}
func (e *Engine) startCmd(cmd string) (*exec.Cmd, io.ReadCloser, io.ReadCloser, error) {
c := exec.Command("/bin/sh", "-c", cmd)
f, err := pty.Start(c)
return c, f, f, err
}