fix: Send SIGTERM to child process when parent gets terminated

This commit is contained in:
ptrcnull 2022-01-18 15:29:42 +01:00
parent 66aeae6166
commit ff7ac9ad75

10
main.go
View file

@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"os/signal"
"strings"
"syscall"
)
@ -46,6 +47,15 @@ func main() {
fmt.Printf("failed to start: %s\n", err)
}
sigs := make(chan os.Signal, 1)
go func() {
for {
_ = <-sigs
cmd.Process.Signal(syscall.SIGTERM)
}
}()
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
err = cmd.Wait()
if err != nil {
fmt.Printf("process exited with error: %s\n", err)