Avoid child processes

This commit is contained in:
Manuel de Brito Fontes 2017-04-09 13:58:03 -03:00
parent 7c635a8c83
commit 1c6c4273c9

View file

@ -28,6 +28,14 @@ import (
)
func main() {
callback := func(pid int, wstatus syscall.WaitStatus) {
glog.V(2).Infof("removing child process pid %d, wstatus: %+v\n", pid, wstatus)
}
sig := make(chan os.Signal, 1024)
signal.Notify(sig, syscall.SIGCHLD)
go reapChildren(sig, callback)
// start a new nginx controller
ngx := newNGINXController()
// create a custom Ingress controller using NGINX as backend
@ -58,3 +66,18 @@ func handleSigterm(ic *controller.GenericController) {
glog.Infof("Exiting with %v", exitCode)
os.Exit(exitCode)
}
func reapChildren(signal chan os.Signal, callback func(int, syscall.WaitStatus)) {
for {
<-signal
for {
var status syscall.WaitStatus
pid, _ := syscall.Wait4(-1, &status, 0, nil)
if pid <= 0 {
break
}
callback(pid, status)
break
}
}
}