As far as I know, process substitution in bash and FIFO (created by mkfifo
) are both named pipes. They both seem viable solutions for communication between processes. I was wondering how to decide when to use which? Thanks.

- 101,790
1 Answers
Process substitution doesn’t necessarily involved named pipes; it can be implemented using /dev/fd
on platforms which support that.
At least with Bash on Linux, process substitution is significantly faster than FIFOs. Based on Performance differences between pipelines and process substitution, I used the following script to test FIFOs:
mkfifo fifo
for i in {1..10000}; do
echo foo bar > fifo &
while read; do
echo $REPLY > /dev/null
done < fifo
done
rm fifo
and ended up with similar timings to those given for pipes in the linked question.
With Zsh, the performance difference isn’t as dramatic, but it is still present (approximately 10% in favour of process substitution).
Apart from that I don’t think there’s much practical difference. You can use FIFOs in (some) GUIs, unlike process substitution (except in cases where the GUI ignores its command-line). You can also create a FIFO and use one of its ends without immediately connecting the other end, again unlike process substitution.

- 434,908
/dev/fd/
, which we can look up in GUIs? – Tim Mar 26 '18 at 04:24/dev/fd
, which could be used in a GUI, except that it’s impossible to separate the definition from the use of this form of pipe, so in practice there’s not much scope for actually putting this to any use. The only exception is with GUI programs which ignore their command line, and then you’re right,/dev/fd
would work. – Stephen Kitt Mar 26 '18 at 04:41mkfifo
) from different shells. Is it the same case for process substitution? In process substitution, the command inside it and the command which uses it are specified in the same command line, so should they be run in the same shell? – Tim Mar 26 '18 at 05:05bash -c "cat <(zsh -c 'echo Hello')"
. – Stephen Kitt Mar 26 '18 at 06:04mkfifo fifo
, we can runcat fifo
in a shell process running in one terminal emulator window, and runecho hello > fifo
in a shell process running in another terminal emulator window. I was wondering if process substitution can work like that or not? (2) As we have seen my previous post that a FIFO created bymkfifo
can be used for nonlinear connection between processes, while a pipe just for linear connection. Can process substitution be used for nonlinear or linear connection? – Tim Mar 26 '18 at 15:13