Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid zombie child processes #577

Merged
merged 1 commit into from
Apr 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions controllers/nginx/pkg/cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}