26 lines
482 B
Go
26 lines
482 B
Go
// Timeout survival: a child in its own session outlives the parent; the PID
|
|
// namespace must take it down with the run.
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"syscall"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
if len(os.Args) > 1 {
|
|
time.Sleep(time.Hour)
|
|
return
|
|
}
|
|
child := exec.Command(os.Args[0], "daemon")
|
|
child.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
|
if err := child.Start(); err != nil {
|
|
fmt.Println("start failed:", err)
|
|
return
|
|
}
|
|
fmt.Println("parent done")
|
|
}
|