func Start(config Config) {
	if !config.DisablePid1Check {
		mypid := os.Getpid()
		if 1 != mypid {
			if config.Debug {
				fmt.Printf(" - Grim reaper disabled, pid not 1\n")
			}
			return
		}
	}
	go reapChildren(config)
}
Entry point for invoking the reaper code with a specific configuration.
The config allows you to bypass the pid 1 checks, so handle with care.
The child processes are reaped in the background inside a goroutine.
package reaper
import "fmt"
import "os"
import "os/signal"
import "syscall"
type Config struct {
	Pid              int
	Options          int
	DisablePid1Check bool
	Debug            bool
}
func sigChildHandler(notifications chan os.Signal) {
	var sigs = make(chan os.Signal, 3)
	signal.Notify(sigs, syscall.SIGCHLD)
	for {
		var sig = <-sigs
		select {
		case notifications <- sig:  
		default:
		}
	}
}  
func reapChildren(config Config) {
	var notifications = make(chan os.Signal, 1)
	go sigChildHandler(notifications)
	pid := config.Pid
	opts := config.Options
	for {
		var sig = <-notifications
		if config.Debug {
			fmt.Printf(" - Received signal %v\n", sig)
		}
		for {
			var wstatus syscall.WaitStatus
			pid, err := syscall.Wait4(pid, &wstatus, opts, nil)
			for syscall.EINTR == err {
				pid, err = syscall.Wait4(pid, &wstatus, opts, nil)
			}
			if syscall.ECHILD == err {
				break
			}
			if config.Debug {
				fmt.Printf(" - Grim reaper cleanup: pid=%d, wstatus=%+v\n",
					pid, wstatus)
			}
		}
	}
}  
func Reap() {
	Start(Config{
		Pid:              -1,
		Options:          0,
		DisablePid1Check: false,
	})
}  