pipe(2) pipe(2)
NAME
pipe - create an interprocess channel
SYNOPSIS
#include <unistd.h>
int pipe(int fildes[2]);
DESCRIPTION
pipe creates an I/O mechanism called a pipe and returns two
file descriptors, fildes[0] and fildes[1]. The files
associated with fildes[0] and fildes[1] are streams and are
both opened for reading and writing. The O_NDELAY and
O_NONBLOCK flags are cleared.
A read from fildes[0] accesses the data written to fildes[1]
on a first-in-first-out (FIFO) basis and a read from fildes[1]
accesses the data written to fildes[0] also on a FIFO basis.
The FD_CLOEXEC flag will be clear on both file descriptors.
If pipe succeeds, it marks for update the st_atime, st_ctime,
and st_mtime fields of the pipe.
Return Values
On success, pipe returns 0. On failure, pipe returns -1 and
sets errno to identify the error.
Errors
In the following conditions, pipe fails and sets errno to:
EMFILE The maximum number of file descriptors are
currently open.
ENFILE A file table entry could not be allocated.
REFERENCES
fcntl(2), getmsg(2), poll(2), putmsg(2), read(2), sh(1),
stat(2), streamio(7), write(2)
NOTICES
Since a pipe is bi-directional, there are two separate flows
of data. Therefore, the size (st_size) returned by a call to
fstat with argument fildes[0] or fildes[1] is the number of
bytes available for reading from fildes[0] or fildes[1]
respectively. Previously, the size (st_size) returned by a
call to fstat with argument fildes[1] (the write-end) was the
Copyright 1994 Novell, Inc. Page 1
pipe(2) pipe(2)
number of bytes available for reading from fildes[0] (the
read-end). See stat(2).
Considerations for Threads Programming
Open file descriptors are a process resource and available to
any sibling thread; if used concurrently, actions by one
thread can interfere with those of a sibling. For example,
data read from a pipe (destructive) by one thread is not
available to siblings.
Copyright 1994 Novell, Inc. Page 2