This commit is contained in:
2024-08-27 15:46:23 +08:00
commit 715eda7c67
70 changed files with 20484 additions and 0 deletions

41
sigchld_unix.go Normal file
View File

@@ -0,0 +1,41 @@
// +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
}
}
}