telegraf/internal/process/process_posix.go

29 lines
458 B
Go
Raw Normal View History

2020-06-05 07:09:22 +08:00
// +build !windows
package process
import (
"os/exec"
"syscall"
"time"
)
func gracefulStop(cmd *exec.Cmd, timeout time.Duration) {
time.AfterFunc(timeout, func() {
2020-06-27 04:38:07 +08:00
if cmd.ProcessState == nil {
2020-06-05 07:09:22 +08:00
return
}
if !cmd.ProcessState.Exited() {
cmd.Process.Signal(syscall.SIGTERM)
time.AfterFunc(timeout, func() {
2020-06-27 04:38:07 +08:00
if cmd.ProcessState == nil {
2020-06-05 07:09:22 +08:00
return
}
if !cmd.ProcessState.Exited() {
cmd.Process.Kill()
}
})
}
})
}