You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Otherwise, during the execution of the command a separate goroutine
// reads from the process over a pipe and delivers that data to the
// corresponding Writer. In this case, Wait does not complete until the
// goroutine reaches EOF or encounters an error or a nonzero WaitDelay
// expires.
In particular, Wait does not complete until EOF from stdout.
In your case, in a, a pipe is connected to cmd.Stdout (where the cmd is b), which is b's os.Stdout, which in b is connected to cmd.Stdout (where the cmd is tail). So, a's cmd.Stdout pipe is eventually connected to tail's stdout.
When a terminates b with a signal, b does not send a signal to kill tail, nor does it close tail's stdin, so tail is still running and its stdout is still open. Therefore, in a, cmd.Stdout has not reached EOF and so Wait does not complete, as documented. Run uses Wait to wait for the process exit, so it also does not complete.
If either in a you don't connect cmd.Stdout to a pipe, or in b you don't connect cmd.Stdout to os.Stdout, Run will return.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
a.go:
b.go:
After building the binaries and putting them in the same directory, I run
./a
.What did you expect to see?
The program prints
Run returned.
in 5 seconds and exits.What did you see instead?
Kill: os: process already finished
The program doesn't exit until I press Ctrl+C.
The text was updated successfully, but these errors were encountered: