toolbox sleeper: reap inherited child processes

This commit is contained in:
Simone Gotti 2019-05-10 14:28:56 +02:00
parent ba5399b97e
commit f8b0061844
1 changed files with 22 additions and 0 deletions

View File

@ -15,6 +15,9 @@
package cmd
import (
"os"
"os/signal"
"syscall"
"time"
"github.com/spf13/cobra"
@ -30,7 +33,26 @@ func init() {
CmdToolbox.AddCommand(cmdSleeper)
}
func childsReaper() {
var sigs = make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGCHLD)
for {
for range sigs {
for {
var wstatus syscall.WaitStatus
if _, err := syscall.Wait4(-1, &wstatus, syscall.WNOHANG|syscall.WUNTRACED|syscall.WCONTINUED, nil); err == syscall.EINTR {
continue
}
break
}
}
}
}
func sleeperRun(cmd *cobra.Command, args []string) {
go childsReaper()
time.Sleep(100 * time.Hour)
//c := make(chan struct{})
//<-c