Created
October 14, 2015 16:52
-
-
Save siennathesane/34fa87cbf8005b161c5b to your computer and use it in GitHub Desktop.
Function used to reap all child process...also known as...child reaper...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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