'\"macro stdmacro
.if n .pH g2.pipe @(#)pipe	40.19 of 10/10/89
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} pipe 2 "" "\&"
.if \nX=1 .ds x} pipe 2 ""
.if \nX=2 .ds x} pipe 2 "" "\&"
.if \nX=3 .ds x} pipe "" "" "\&"
.TH \*(x}
.SH NAME
\f4pipe\f1 \- create an interprocess channel
.SH SYNOPSIS
\f4#include <unistd.h>
.PP
\f4int pipe(int fildes[2]);\f1
.SH DESCRIPTION
\f4pipe\fP
creates an \s-1I/O\s0 mechanism called a pipe and returns two file descriptors,
\f2fildes\f4[0]\f1
and
\f2fildes\f4[1]\f1.
The files associated with \f2fildes\f4[0]\f1 and \f2fildes\f4[1]\f1 are
streams and are both opened for reading and writing. 
The \f4O_NDELAY\f1 and \f4O_NONBLOCK\f1 flags are cleared.
.PP
A read from \f2fildes\f4[0]\f1 accesses the data written to \f2fildes\f4[1]\f1
on a first-in-first-out (\s-1FIFO\s+1) basis and a read from \f2fildes\f4[1]\f1
accesses the data written to \f2fildes\f4[0]\f1 also on a FIFO basis.
.PP
The \f4FD_CLOEXEC\f1 flag will be clear on both file descriptors.
.PP
Upon successful completion \f4pipe\fP marks for update the
\f4st_atime, st_ctime\f1, and \f4st_mtime\f1 fields of the pipe.
.PP
\f4pipe\fP
fails if:
.TP 15
\f4EMFILE\fP
If \f4{OPEN_MAX}-1\f1 or more file descriptors are currently open for this process.
.TP
\f4ENFILE\fP
A file table entry could not be allocated.
.SH "SEE ALSO"
\f4fcntl\fP(2), \f4getmsg\fP(2), \f4poll\fP(2), \f4putmsg\fP(2),
\f4read\fP(2), \f4write\fP(2), \f4streamio\fP(7).
.sp .2
\f4sh\fP(1) in the
\f2User's Reference Manual\f1.
.SH "DIAGNOSTICS"
Upon successful completion,
a value of 0
is returned.
Otherwise, a value of \-1 is returned and
\f4errno\fP
is set to indicate the error.
.SH "NOTES"
Since a pipe is bi-directional, there are two separate flows of data.
Therefore, the size (\f4st_size\fP) returned by a call to \f4fstat\fP(2)
with argument 
\f2fildes\f4[0]\f1 or
\f2fildes\f4[1]\f1
is the number of bytes available for reading from
\f2fildes\f4[0]\f1 or
\f2fildes\f4[1]\f1
respectively.
Previously, the size
(\f4st_size\fP) returned by a call to
\f4fstat\fP(\)
with argument
\f2fildes\f4[1]\f1
(the write-end) was the number of bytes available for reading from
\f2fildes\f4[0]\f1 (the read-end).
.\"	@(#)pipe.2	6.2 of 9/6/83
.Ee
