in lambda/supervisor/local_supervisor.go [147:184]
func kill(p process, name string, deadline time.Time) error {
// kill should report success if the process terminated by the time
//supervisor receives the request.
select {
// if this case is selected, the channel is closed,
// which means the process is terminated
case <-p.termination:
log.Debugf("Process %s already terminated.", name)
return nil
default:
log.Infof("Sending SIGKILL to %s(%d).", name, p.pid)
}
if (time.Since(deadline)) > 0 {
return fmt.Errorf("invalid timeout while killing %s", name)
}
pgid, err := syscall.Getpgid(p.pid)
if err == nil {
// Negative pid sends signal to all in process group
syscall.Kill(-pgid, syscall.SIGKILL)
} else {
syscall.Kill(p.pid, syscall.SIGKILL)
}
ctx, cancel := context.WithDeadline(context.Background(), deadline)
defer cancel()
// block until the (main) process exits
// or the timeout fires
select {
case <-p.termination:
return nil
case <-ctx.Done():
return fmt.Errorf("timed out while trying to SIGKILL %s", name)
}
}