I think for the linux command, the pipeline: $ command1 | command2 | command3 will execute with sequence command1 -> command2 -> command3.

But what about using tee: $ command1 | tee >(command2) >(command3)

Since that command2 and command3 have the same input, my question is, will command2 and command3 execute in parallel (multithread?) or in sequence 2->3?

Thanks.

They will execute in parallel if they are capable of doing so. The tee command will feed input to both commands as it gets it. This will make them "ready to run" if they were blocked on input, and then the OS wills schedule them on whatever cores it has available. This is not multithreading because that takes place within a process. This is multiprocess operation.

Try running this command (Ctrl-C it after a bit):

(od -x /dev/urandom | tee >(sed 's/^/1 /') >(sed 's/^/2 /')) > /tmp/output

/tmp/output will be interleaved and overwritten as each process gets a chance to run.

Also when you say "will execute with sequence" that's incorrect. I think DOS used to simulate pipelines with temporary files, but not Unix.

(I've never seen the >() syntax before. Learn something new everyday!)

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.