Skip to content

Instantly share code, notes, and snippets.

@siennathesane
Created October 14, 2015 16:52
Show Gist options
  • Select an option

  • Save siennathesane/34fa87cbf8005b161c5b to your computer and use it in GitHub Desktop.

Select an option

Save siennathesane/34fa87cbf8005b161c5b to your computer and use it in GitHub Desktop.
Function used to reap all child process...also known as...child reaper...
func ChildReaper() (exits []Exit, err error) {
//start the loop to reap any abandonded children.
for {
var (
status syscall.WaitStatus
usage syscall.Rusage
)
// make the `wait4` call and check for errors. if the error equals
// ECHILD (no child process), return empty exit status.
processID, err := syscall.Wait4(-1, &status, syscall.WNOHANG, &usage)
if err != nil {
if err == syscall.ECHILD {
return exits, nil
}
}
// shows which processes have exited and with what status.
exits = append(exits, Exit{
processID, status.ExitStatus(),
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment