catch SIGCHLD signals

master
codeskyblue 7 years ago
parent 6b7940ac7d
commit 43f15bfdc3

@ -3,17 +3,35 @@
package main
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/qiniu/log"
)
func init() {
go reapChildren()
}
func childSignal(notify chan bool) {
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.
}
}
}
func reapChildren() {
var wstatus syscall.WaitStatus
notify := make(chan bool, 1)
go childSignal(notify)
for {
pid, err := syscall.Wait4(-1, &wstatus, 0, nil)

Loading…
Cancel
Save