fix: Send SIGTERM to child process when parent gets terminated
This commit is contained in:
parent
66aeae6166
commit
ff7ac9ad75
1 changed files with 10 additions and 0 deletions
10
main.go
10
main.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
@ -46,6 +47,15 @@ func main() {
|
||||||
fmt.Printf("failed to start: %s\n", err)
|
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()
|
err = cmd.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("process exited with error: %s\n", err)
|
fmt.Printf("process exited with error: %s\n", err)
|
||||||
|
|
Loading…
Reference in a new issue