github.com/yujinakayama/air@v0.0.0-20220811130100-b77a59dfa933/runner/util_linux.go (about) 1 package runner 2 3 import ( 4 "io" 5 "os/exec" 6 "syscall" 7 "time" 8 9 "github.com/creack/pty" 10 ) 11 12 func (e *Engine) killCmd(cmd *exec.Cmd) (pid int, err error) { 13 pid = cmd.Process.Pid 14 15 if e.config.Build.SendInterrupt { 16 // Sending a signal to make it clear to the process that it is time to turn off 17 if err = syscall.Kill(-pid, syscall.SIGINT); err != nil { 18 return 19 } 20 time.Sleep(e.config.Build.KillDelay) 21 } 22 23 // https://stackoverflow.com/questions/22470193/why-wont-go-kill-a-child-process-correctly 24 err = syscall.Kill(-pid, syscall.SIGKILL) 25 26 // Wait releases any resources associated with the Process. 27 _, _ = cmd.Process.Wait() 28 return 29 } 30 31 func (e *Engine) startCmd(cmd string) (*exec.Cmd, io.ReadCloser, io.ReadCloser, error) { 32 c := exec.Command("/bin/sh", "-c", cmd) 33 f, err := pty.Start(c) 34 return c, f, f, err 35 }