From be857aaa20d961e90c6ce3d3ee8addbc2ec3d492 Mon Sep 17 00:00:00 2001 From: codeskyblue Date: Wed, 12 Jul 2017 11:44:57 +0800 Subject: [PATCH] make recyle zombie more simple --- sigchld_unix.go | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/sigchld_unix.go b/sigchld_unix.go index e577e5b..65ed255 100644 --- a/sigchld_unix.go +++ b/sigchld_unix.go @@ -3,44 +3,26 @@ package main import ( - "log" "os" "os/signal" "syscall" ) func init() { - go reapChildren() + go watchChildSignal() } -func childSignal(notify chan bool) { +func watchChildSignal() { var sigs = make(chan os.Signal, 3) signal.Notify(sigs, syscall.SIGCHLD) for { <-sigs - select { - case notify <- true: - default: - // Channel full, does not matter as we wait for all children. - } + reapChildren() } } func reapChildren() { var wstatus syscall.WaitStatus - notify := make(chan bool, 1) - - go childSignal(notify) - - for { - pid, err := syscall.Wait4(-1, &wstatus, 0, nil) - for err == syscall.EINTR { - pid, err = syscall.Wait4(-1, &wstatus, 0, nil) - } - if err == syscall.ECHILD { - break - } - log.Printf("pid %d, finished, wstatus: %+v", pid, wstatus) - } + syscall.Wait4(-1, &wstatus, syscall.WNOHANG, nil) }