последовательность процессов конвейера / тройника linux

434
vivienlwt

Я думаю, что для команды Linux, конвейер: $ command1 | command2 | command3 будет выполняться с последовательностью команда1 -> команда2 -> команда3.

Но как насчет использования тройника: $ command1 | tee >(command2) >(command3)

Так как это command2и command3имеет тот же вход, мой вопрос, будет command2и будет command3выполняться параллельно (многопоточность?) Или в последовательности 2-> 3?

Благодарю.

1

2 ответа на вопрос

2
David Schwartz

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.

0
Emery Lapinski

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!)

Похожие вопросы