Can stdout be overwritten by two bourne (or bash, if that matters) subshell commands running asynchronously?
(tail -f ./file1 & tail -f ./file2) | cat
I don’t care about the line order, just that every output line is made up of exactly one input line. I’m worried that some lines could be partially overwritten or interleaved.
I’ve tested this by running four commands that each output a unique line 15 million times each. It appears to work, but I kind of expected it to fail.
Can someone explain how this doesn’t break? Is each subshell buffered and only one subshell gets to write to stdout at a time? or how is this managed.
Is there a better way to do this?
(Never mind that I’m using
tail in the above subshells for illustrative purposes. I actually want to run two other commands that output continuously one line at the time to stdout.)