I was wondering why the relations between the processes which can be used by pipes are different in Linux API and Bash.
In Linux API, unnamed pipes (
pipe()
) can be used only between parent-child processes.In Bash, pipes can be used between two processes which have a shell process as their common parent.
Are pipes in Bash implemented in terms of unnamed pipes in Linux API? Thanks.
From APUE 3ed:
15.2 Pipes
Pipes are the oldest form of UNIX System IPC and are provided by all UNIX systems. Pipes have two limitations.
Historically, they have been half duplex (i.e., data flows in only one direction). Some systems now provide full-duplex pipes, but for maximum portability, we should never assume that this is the case.
Pipes can be used only between processes that have a common ancestor. Normally, a pipe is created by a process, that process calls fork, and the pipe is used between the parent and the child.
We’ll see that FIFOs (Section 15.5) get around the second limitation, and that UNIX domain sockets (Section 17.2) get around both limitations.
...
15.5 FIFOs
FIFOs are sometimes called named pipes. Unnamed pipes can be used only between related processes when a common ancestor has created the pipe. With FIFOs, however, unrelated processes can exchange data.