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 //go:build go1.20 6 7 package main 8 9 import ( 10 "os" 11 "os/exec" 12 "time" 13 ) 14 15 func cmdInterrupt(cmd *exec.Cmd) { 16 cmd.Cancel = func() error { 17 // On timeout, send interrupt, 18 // in hopes of shutting down process tree. 19 // Ignore errors sending signal; it's all best effort 20 // and not even implemented on Windows. 21 // TODO(rsc): Maybe use a new process group and kill the whole group? 22 cmd.Process.Signal(os.Interrupt) 23 return nil 24 } 25 cmd.WaitDelay = 2 * time.Second 26 } 27