Pipe I/O
POSIX.1 pipes represent an I/O channel that processes can use to communicate with other processes. Pipes are conceptually like z/OS® UNIX file system files. One process can write data into a pipe, and another process can read data from the pipe.
z/OS UNIX XL C/C++ supports two types of POSIX.1-defined pipes: unnamed pipes and named pipes (FIFO files).
An unnamed pipe is accessible only by the process that created
the pipe and its child processes. An unnamed pipe does not have to
be opened before it can be used. It is a temporary file that lasts
only until the last file descriptor that references it is closed.
You can create an unnamed pipe by calling the pipe()
function.
A named pipe can be used by independent processes and must
be explicitly opened and closed. Named pipes are also referred to
as first-in, first-out (FIFO) files, or FIFOs. You can create a named
pipe by calling the mkfifo()
function.
If you want to stream I/O after a pipe()
function,
call the fdopen()
function to build a stream on one
of the file descriptors returned by pipe()
. If you
want to stream I/O on a FIFO file, open the file with fdopen()
together
with one of fopen()
, freopen()
,
or open()
. When the stream is built, you can then
use Standard C I/O functions, such as fgets()
or printf()
, to
carry out input and output.