From 6b7940ac7d06cd31c83ad9215cf1a285ea67216d Mon Sep 17 00:00:00 2001 From: codeskyblue Date: Tue, 11 Jul 2017 16:58:32 +0800 Subject: [PATCH] fix #26 --- sigchld_unix.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 sigchld_unix.go diff --git a/sigchld_unix.go b/sigchld_unix.go new file mode 100644 index 0000000..24ef95e --- /dev/null +++ b/sigchld_unix.go @@ -0,0 +1,28 @@ +// +build linux darwin + +package main + +import ( + "syscall" + + "github.com/qiniu/log" +) + +func init() { + go reapChildren() +} + +func reapChildren() { + var wstatus syscall.WaitStatus + + 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) + } +}