进入wait4功能

I want to test wait4 function, but I'm not really familiar with child processes and so on, but I need to keep it working and during this time send it some signal and see reaction. Can you give me a little example of using wait4 in Go?

wait4 is deprecated on Linux, the proper way is to use exec.Command and call .Wait().

An example with signals:

func bgProcess(app string) (chan error, *os.Process, error) {
    cmd := exec.Command(app)
    ch := make(chan error, 1)
    if err := cmd.Start(); err != nil {
        return nil, nil, err
    }
    go func() {
        ch <- cmd.Wait()
    }()
    return ch, cmd.Process, nil
}
func main() {
    ch, proc, err := bgProcess("/usr/bin/cat")
    if err != nil {
        log.Fatal(err)
    }
    log.Println("Signal(os.Kill):", proc.Signal(os.Kill))
    log.Println("cat returned:", <-ch)

}