// Terminate tries to gracefully shutdown a process by sending SIGTERM.
// If the process does not shut down after (at least) gracePeriod a SIGKILL will be sent.
// 10 checks will be done during gracePeriod to check if the process is still
// alive. If a gracePeriod of 0 is passed SIGKILL will be send immediately.
Terminate tries to gracefully shutdown a process by sending SIGTERM.
If the process does not shut down after (at least) gracePeriod a SIGKILL will be sent.
10 checks will be done during gracePeriod to check if the process is still
alive. If a gracePeriod of 0 is passed SIGKILL will be send immediately.
// Terminate tries to gracefully shutdown a process by sending SIGTERM . // If the process does not shut down after ( at least ) gracePeriod a SIGKILL will be sent . // 10 checks will be done during gracePeriod to check if the process is still // alive . If a gracePeriod of 0 is passed SIGKILL will be send immediately .
func Terminate(proc *os.Process, gracePeriod time.Duration) error {
	if gracePeriod > 0 {
		err := proc.Signal(syscall.SIGTERM)
		if err != nil {
			return err
		}
		stepDuration := gracePeriod / 10
		for i := 0; i < 10; i++ {
			time.Sleep(stepDuration)
			if err := proc.Signal(syscall.Signal(0)); err != nil {
				return nil 
			}
		}
	}
	return proc.Kill()
}
func Terminate ( proc * os . Process , gracePeriod time . Duration ) error { if gracePeriod > 0 { err := proc . Signal ( syscall . SIGTERM ) if err != nil { return err } stepDuration := gracePeriod / 10 for i := 0 ; i < 10 ; i ++ { time . Sleep ( stepDuration ) if err := proc . Signal ( syscall . Signal ( 0 ) ) ; err != nil { return nil } } } return proc . Kill ( ) }
Terminate tries to gracefully shutdown a process by sending SIGTERM.
Terminate tries to gracefully shutdown a process by sending SIGTERM .
// Try to gracefully shutdown the process by sending TERMINATE // first. After 5 seconds KILL will be sent. // ### return, success ###