kill terminates the process. On Windows it kills the process directly, whereas on other platforms, a SIGTERM is sent, before forcefully terminating the process after 3 seconds.
()
| 93 | // whereas on other platforms, a SIGTERM is sent, before forcefully terminating |
| 94 | // the process after 3 seconds. |
| 95 | func (c *commandConn) kill() { |
| 96 | if c.cmdExited.Load() { |
| 97 | return |
| 98 | } |
| 99 | c.cmdMutex.Lock() |
| 100 | var werr error |
| 101 | if runtime.GOOS != "windows" { |
| 102 | werrCh := make(chan error) |
| 103 | go func() { werrCh <- c.cmd.Wait() }() |
| 104 | _ = c.cmd.Process.Signal(syscall.SIGTERM) |
| 105 | select { |
| 106 | case werr = <-werrCh: |
| 107 | case <-time.After(3 * time.Second): |
| 108 | _ = c.cmd.Process.Kill() |
| 109 | werr = <-werrCh |
| 110 | } |
| 111 | } else { |
| 112 | _ = c.cmd.Process.Kill() |
| 113 | werr = c.cmd.Wait() |
| 114 | } |
| 115 | c.cmdWaitErr = werr |
| 116 | c.cmdMutex.Unlock() |
| 117 | c.cmdExited.Store(true) |
| 118 | } |
| 119 | |
| 120 | // handleEOF handles io.EOF errors while reading or writing from the underlying |
| 121 | // command pipes. |
no test coverage detected