package supervisor import ( "os" "syscall" ) // killGroup signals a whole process group. // // Engines fork worker processes that hold GPU memory. Signalling only the // leader leaves those workers alive, and the next launch then fails to // allocate — with an error that points at the new process rather than the old. func killGroup(pid int, sig syscall.Signal) error { // The negative pid addresses the group. Setpgid at launch made the leader's // pid the group id. if err := syscall.Kill(-pid, sig); err != nil { if err == syscall.ESRCH { return os.ErrProcessDone } return err } return nil } // processAlive reports whether a pid exists. func processAlive(pid int) bool { if pid <= 0 { return false } // Signal 0 performs the permission and existence checks without delivering // anything. err := syscall.Kill(pid, 0) return err == nil || err == syscall.EPERM }