<s>
In	O
computing	O
,	O
process	B-Device
substitution	I-Device
is	O
a	O
form	O
of	O
inter-process	B-Operating_System
communication	I-Operating_System
that	O
allows	O
the	O
input	O
or	O
output	O
of	O
a	O
command	O
to	O
appear	O
as	O
a	O
file	O
.	O
</s>
<s>
Process	B-Device
substitution	I-Device
was	O
available	O
as	O
a	O
compile-time	O
option	O
for	O
ksh88	B-Language
,	O
the	O
1988	O
version	O
of	O
the	O
KornShell	B-Language
from	O
Bell	O
Labs	O
.	O
</s>
<s>
The	O
rc	B-Operating_System
shell	I-Operating_System
provides	O
the	O
feature	O
as	O
"	O
pipeline	B-Operating_System
branching	O
"	O
in	O
Version	B-Operating_System
10	I-Operating_System
Unix	I-Operating_System
,	O
released	O
in	O
1990	O
.	O
</s>
<s>
The	O
Bash	B-Operating_System
shell	I-Operating_System
provided	O
process	B-Device
substitution	I-Device
no	O
later	O
than	O
version	O
1.14	O
,	O
released	O
in	O
1994	O
.	O
</s>
<s>
The	O
following	O
examples	O
use	O
KornShell	B-Language
syntax	O
.	O
</s>
<s>
The	O
Unix	B-Application
diff	B-Application
command	O
normally	O
accepts	O
the	O
names	O
of	O
two	O
files	O
to	O
compare	O
,	O
or	O
one	O
file	O
name	O
and	O
standard	O
input	O
.	O
</s>
<s>
Process	B-Device
substitution	I-Device
allows	O
one	O
to	O
compare	O
the	O
output	O
of	O
two	O
programs	O
directly	O
:	O
</s>
<s>
Without	O
process	B-Device
substitution	I-Device
,	O
the	O
alternatives	O
are	O
:	O
</s>
<s>
Process	B-Device
substitution	I-Device
can	O
also	O
be	O
used	O
to	O
capture	O
output	O
that	O
would	O
normally	O
go	O
to	O
a	O
file	O
,	O
and	O
redirect	O
it	O
to	O
the	O
input	O
of	O
a	O
process	O
.	O
</s>
<s>
The	O
Bash	B-Operating_System
syntax	O
for	O
writing	O
to	O
a	O
process	O
is	O
>(command )	O
.	O
</s>
<s>
Here	O
is	O
an	O
example	O
using	O
the	O
tee	B-Operating_System
,	O
wc	B-Application
and	O
gzip	B-Application
commands	O
that	O
counts	O
the	O
lines	O
in	O
a	O
file	O
with	O
wc	B-Application
-l	O
and	O
compresses	O
it	O
with	O
gzip	B-Application
in	O
one	O
pass	O
:	O
</s>
<s>
The	O
main	O
advantages	O
of	O
process	B-Device
substitution	I-Device
over	O
its	O
alternatives	O
are	O
:	O
</s>
<s>
Simplicity	O
:	O
The	O
commands	O
can	O
be	O
given	O
in-line	O
;	O
there	O
is	O
no	O
need	O
to	O
save	O
temporary	O
files	O
or	O
create	O
named	B-Operating_System
pipes	I-Operating_System
first	O
.	O
</s>
<s>
Parallelism	O
:	O
The	O
substituted	O
process	O
can	O
be	O
running	O
concurrently	O
with	O
the	O
command	O
reading	O
its	O
output	O
or	O
writing	O
its	O
input	O
,	O
taking	O
advantage	O
of	O
multiprocessing	B-Operating_System
to	O
reduce	O
the	O
total	O
time	O
for	O
the	O
computation	O
.	O
</s>
<s>
Under	O
the	O
hood	O
,	O
process	B-Device
substitution	I-Device
has	O
two	O
implementations	O
.	O
</s>
<s>
On	O
systems	O
which	O
support	O
/dev/fd	O
(	O
most	O
Unix-like	O
systems	O
)	O
it	O
works	O
by	O
calling	O
the	O
pipe( )	O
system	O
call	O
,	O
which	O
returns	O
a	O
file	O
descriptor	O
$fd	O
for	O
a	O
new	O
anonymous	B-Operating_System
pipe	I-Operating_System
,	O
then	O
creating	O
the	O
string	O
/dev/fd/	O
$fd	O
,	O
and	O
substitutes	O
that	O
on	O
the	O
command	O
line	O
.	O
</s>
<s>
On	O
systems	O
without	O
/dev/fd	O
support	O
,	O
it	O
calls	O
mkfifo	O
with	O
a	O
new	O
temporary	O
filename	O
to	O
create	O
a	O
named	B-Operating_System
pipe	I-Operating_System
,	O
and	O
substitutes	O
this	O
filename	O
on	O
the	O
command	O
line	O
.	O
</s>
<s>
To	O
illustrate	O
the	O
steps	O
involved	O
,	O
consider	O
the	O
following	O
simple	O
command	B-Device
substitution	I-Device
on	O
a	O
system	O
with	O
/dev/fd	O
support	O
:	O
</s>
<s>
Create	O
a	O
new	O
anonymous	B-Operating_System
pipe	I-Operating_System
.	O
</s>
<s>
Execute	O
the	O
substituted	O
command	O
in	O
the	O
background	O
(	O
sort	O
file2	O
in	O
this	O
case	O
)	O
,	O
piping	O
its	O
output	O
to	O
the	O
anonymous	B-Operating_System
pipe	I-Operating_System
.	O
</s>
<s>
Execute	O
the	O
primary	O
command	O
,	O
replacing	O
the	O
substituted	O
command	O
with	O
the	O
path	O
of	O
the	O
anonymous	B-Operating_System
pipe	I-Operating_System
.	O
</s>
<s>
In	O
this	O
case	O
,	O
the	O
full	O
command	O
might	O
expand	O
to	O
something	O
like	O
diff	B-Application
file1	O
/dev/fd/63	O
.	O
</s>
<s>
When	O
execution	O
is	O
finished	O
,	O
close	O
the	O
anonymous	B-Operating_System
pipe	I-Operating_System
.	O
</s>
<s>
For	O
named	B-Operating_System
pipes	I-Operating_System
,	O
the	O
execution	O
differs	O
solely	O
in	O
the	O
creation	O
and	O
deletion	O
of	O
the	O
pipe	O
;	O
they	O
are	O
created	O
with	O
mkfifo	O
(	O
which	O
is	O
given	O
a	O
new	O
temporary	O
file	O
name	O
)	O
and	O
removed	O
with	O
unlink	O
.	O
</s>
<s>
The	O
"	O
files	O
"	O
created	O
are	O
not	O
seekable	O
,	O
which	O
means	O
the	O
process	O
reading	O
or	O
writing	O
to	O
the	O
file	O
cannot	O
perform	O
random	B-General_Concept
access	I-General_Concept
;	O
it	O
must	O
read	O
or	O
write	O
once	O
from	O
start	O
to	O
finish	O
.	O
</s>
<s>
Programs	O
that	O
explicitly	O
check	O
the	O
type	O
of	O
a	O
file	O
before	O
opening	O
it	O
may	O
refuse	O
to	O
work	O
with	O
process	B-Device
substitution	I-Device
,	O
because	O
the	O
"	O
file	O
"	O
resulting	O
from	O
process	B-Device
substitution	I-Device
is	O
not	O
a	O
regular	O
file	O
.	O
</s>
<s>
Additionally	O
,	O
up	O
to	O
Bash	B-Operating_System
4.4	O
(	O
released	O
September	O
2016	O
)	O
,	O
it	O
was	O
not	O
possible	O
to	O
obtain	O
the	O
exit	O
code	O
of	O
a	O
process	B-Device
substitution	I-Device
command	O
from	O
the	O
shell	O
that	O
created	O
the	O
process	B-Device
substitution	I-Device
.	O
</s>
