| 1 | // Copyright 2023 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package main |
| 6 | |
| 7 | import ( |
| 8 | "os" |
| 9 | "os/exec" |
| 10 | "time" |
| 11 | ) |
| 12 | |
| 13 | func cmdInterrupt(cmd *exec.Cmd) { |
| 14 | cmd.Cancel = func() error { |
| 15 | // On timeout, send interrupt, |
| 16 | // in hopes of shutting down process tree. |
| 17 | // Ignore errors sending signal; it's all best effort |
| 18 | // and not even implemented on Windows. |
| 19 | // TODO(rsc): Maybe use a new process group and kill the whole group? |
| 20 | cmd.Process.Signal(os.Interrupt) |
| 21 | return nil |
| 22 | } |
| 23 | cmd.WaitDelay = 2 * time.Second |
| 24 | } |