From 6db5ba9acf7487b4fad592445e74bdb516d7f9c7 Mon Sep 17 00:00:00 2001
From: Andre Noll The pipe(2)
system call takes no arguments and
creates two file descriptors for the calling process which are tied
-together as a unidirectional first in, first out data channel that
-works just like a fifo, but without any files being involved. One
+together as a unidirectional first in, first out data channel. One
file descriptor is the read end of the pipe, the other is
the write end. Data written to the write end is buffered by
the kernel and can be obtained by reading from the read end.
This approach depends on file descriptor inheritance across
+fork(2)
, so it does not work in the situation
+where neither process is an ancestor of the other. Files of
+type fifo (named pipes) overcome this restriction. To
+establish a connection between two unrelated processes,
+both processes call open(2)
to obtain a file
+descriptor which is associated with the fifo. One process passes
+the O_WRONLY
flag to open the file for writing while
+the other passes O_RDONLY
to open it for reading. The
+two processes may then communicate in the same way as with the
+pipe(2)/fork(2)
approach.
The POSIX dup(2)
and dup2(2)
system
calls allow a process to manipulate the entries of its file descriptor
array. In particular the standard file descriptors 0, 1, and 2 can be
@@ -1827,12 +1838,6 @@ with wc(1)
. Since ls(1)
writes to stdout
and wc(1)
reads from stdin, wc(1)
processes
the output of ls(1)
.
Note that this trick does not work to establish a connection
-between two existing processes because it depends on file
-descriptor inheritance across fork(2)
. In the general
-case one has to fall back to sockets or fifos to create the data
-channel.
The POSIX standard requires a compliant Unix system to provide -- 2.39.5