I have the following code in Go:
cmd := exec.Command(...)
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
cmd.Run()
Which spawns another Go program as a child process and sets its Stdin, Stdout, and Stderr to that of the parent. After the child is spawned, I want to kill the parent via os.Exit()
in the parent process or syscall.Kill(os.Getppid(), syscall.SIGTERM)
in the child. The problem arises after I kill the parent. It seems to close Stdin, so the child can't receive input from the terminal where the parent was spawned.
I can receive input on the child before I kill the parent, so it's definitely the action of killing the parent that closes Stdin. Is there any way I can work around this?
execve
syscall for (syscall.Exec
in go). – JimB