You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
592 B
42 lines
592 B
// +build linux darwin
|
|
|
|
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
)
|
|
|
|
func init() {
|
|
go watchChildSignal()
|
|
}
|
|
|
|
func watchChildSignal() {
|
|
var sigs = make(chan os.Signal, 3)
|
|
signal.Notify(sigs, syscall.SIGCHLD)
|
|
|
|
for {
|
|
<-sigs
|
|
reapChildren()
|
|
}
|
|
}
|
|
|
|
func reapChildren() {
|
|
for {
|
|
var wstatus syscall.WaitStatus
|
|
wpid, err := syscall.Wait4(-1, &wstatus, syscall.WNOHANG, nil)
|
|
if err != nil {
|
|
log.Printf("syscall.Wait4 call failed: %v", err)
|
|
break
|
|
}
|
|
|
|
if wpid != 0 {
|
|
log.Printf("reap dead child: %d, wstatus: %#08x", wpid, wstatus)
|
|
} else {
|
|
break
|
|
}
|
|
}
|
|
}
|