xref: /minix3/lib/libc/sys/pipe.2 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc.\"	$NetBSD: pipe.2,v 1.30 2014/02/22 17:26:41 dholland Exp $
22fe8fb19SBen Gras.\"
32fe8fb19SBen Gras.\" Copyright (c) 1980, 1991, 1993
42fe8fb19SBen Gras.\"	The Regents of the University of California.  All rights reserved.
52fe8fb19SBen Gras.\"
62fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without
72fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions
82fe8fb19SBen Gras.\" are met:
92fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright
102fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer.
112fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
122fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer in the
132fe8fb19SBen Gras.\"    documentation and/or other materials provided with the distribution.
142fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors
152fe8fb19SBen Gras.\"    may be used to endorse or promote products derived from this software
162fe8fb19SBen Gras.\"    without specific prior written permission.
172fe8fb19SBen Gras.\"
182fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
192fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
202fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
212fe8fb19SBen Gras.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
222fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
232fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
242fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
252fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
262fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
272fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
282fe8fb19SBen Gras.\" SUCH DAMAGE.
292fe8fb19SBen Gras.\"
302fe8fb19SBen Gras.\"     @(#)pipe.2	8.1 (Berkeley) 6/4/93
312fe8fb19SBen Gras.\"
32f14fb602SLionel Sambuc.Dd January 23, 2012
332fe8fb19SBen Gras.Dt PIPE 2
342fe8fb19SBen Gras.Os
352fe8fb19SBen Gras.Sh NAME
362fe8fb19SBen Gras.Nm pipe
372fe8fb19SBen Gras.Nd create descriptor pair for interprocess communication
382fe8fb19SBen Gras.Sh LIBRARY
392fe8fb19SBen Gras.Lb libc
402fe8fb19SBen Gras.Sh SYNOPSIS
412fe8fb19SBen Gras.In unistd.h
422fe8fb19SBen Gras.Ft int
432fe8fb19SBen Gras.Fn pipe "int fildes[2]"
44*0a6a1f1dSLionel Sambuc.In unistd.h
45*0a6a1f1dSLionel Sambuc.In fcntl.h
46f14fb602SLionel Sambuc.Ft int
47f14fb602SLionel Sambuc.Fn pipe2 "int fildes[2]" "int flags"
482fe8fb19SBen Gras.Sh DESCRIPTION
492fe8fb19SBen GrasThe
502fe8fb19SBen Gras.Fn pipe
512fe8fb19SBen Grasfunction
522fe8fb19SBen Grascreates a
532fe8fb19SBen Gras.Em pipe ,
542fe8fb19SBen Graswhich is an object allowing
552fe8fb19SBen Grasunidirectional data flow,
562fe8fb19SBen Grasand allocates a pair of file descriptors.
572fe8fb19SBen GrasThe first descriptor connects to the
582fe8fb19SBen Gras.Em read end
592fe8fb19SBen Grasof the pipe,
602fe8fb19SBen Grasand the second connects to the
612fe8fb19SBen Gras.Em write end  ,
622fe8fb19SBen Grasso that data written to
632fe8fb19SBen Gras.Fa fildes[1]
642fe8fb19SBen Grasappears on (i.e., can be read from)
652fe8fb19SBen Gras.Fa fildes[0] .
662fe8fb19SBen GrasThis allows the output of one program to be
672fe8fb19SBen Grassent
682fe8fb19SBen Grasto another program:
692fe8fb19SBen Grasthe source's standard output is set up to be
702fe8fb19SBen Grasthe write end of the pipe,
712fe8fb19SBen Grasand the sink's standard input is set up to be
722fe8fb19SBen Grasthe read end of the pipe.
732fe8fb19SBen GrasThe pipe itself persists until all its associated descriptors are
742fe8fb19SBen Grasclosed.
752fe8fb19SBen Gras.Pp
762fe8fb19SBen GrasA pipe whose read or write end has been closed is considered
772fe8fb19SBen Gras.Em widowed .
782fe8fb19SBen GrasWriting on such a pipe causes the writing process to receive
792fe8fb19SBen Grasa
802fe8fb19SBen Gras.Dv SIGPIPE
812fe8fb19SBen Grassignal.
822fe8fb19SBen GrasWidowing a pipe is the only way to deliver end-of-file to a reader:
832fe8fb19SBen Grasafter the reader consumes any buffered data, reading a widowed pipe
842fe8fb19SBen Grasreturns a zero count.
85f14fb602SLionel Sambuc.Pp
86f14fb602SLionel SambucThe
87f14fb602SLionel Sambuc.Fn pipe2
88f14fb602SLionel Sambucfunction
89f14fb602SLionel Sambucbehaves exactly like
90f14fb602SLionel Sambuc.Fn pipe
91f14fb602SLionel Sambuconly it allows extra
92f14fb602SLionel Sambuc.Fa flags
93f14fb602SLionel Sambucto be set on the returned file descriptor.
94f14fb602SLionel SambucThe following flags are valid:
95f14fb602SLionel Sambuc.Bl -tag -width O_NONBLOCK -offset indent
96f14fb602SLionel Sambuc.It Dv O_CLOEXEC
97f14fb602SLionel SambucSet the
98f14fb602SLionel Sambuc.Dq close-on-exec
99f14fb602SLionel Sambucproperty.
100f14fb602SLionel Sambuc.It Dv O_NONBLOCK
101f14fb602SLionel SambucSets non-blocking I/O.
102f14fb602SLionel Sambuc.It Dv O_NOSIGPIPE
103f14fb602SLionel SambucReturn
104f14fb602SLionel Sambuc.Er EPIPE
105f14fb602SLionel Sambucinstead of raising
106f14fb602SLionel Sambuc.Dv SIGPIPE .
107f14fb602SLionel Sambuc.El
1082fe8fb19SBen Gras.Sh RETURN VALUES
1092fe8fb19SBen GrasOn successful creation of the pipe, zero is returned.
1102fe8fb19SBen GrasOtherwise, a value of \-1 is returned and the variable
1112fe8fb19SBen Gras.Va errno
1122fe8fb19SBen Grasset to indicate the
1132fe8fb19SBen Graserror.
1142fe8fb19SBen Gras.Sh ERRORS
1152fe8fb19SBen GrasThe
1162fe8fb19SBen Gras.Fn pipe
117f14fb602SLionel Sambucand
118f14fb602SLionel Sambuc.Fn pipe2
119f14fb602SLionel Sambuccalls will fail if:
1202fe8fb19SBen Gras.Bl -tag -width Er
1212fe8fb19SBen Gras.It Bq Er EFAULT
1222fe8fb19SBen GrasThe
1232fe8fb19SBen Gras.Fa fildes
1242fe8fb19SBen Grasbuffer is in an invalid area of the process's address space.
1252fe8fb19SBen GrasThe reliable detection of this error cannot be guaranteed; when not
1262fe8fb19SBen Grasdetected, a signal may be delivered to the process, indicating an
1272fe8fb19SBen Grasaddress violation.
128f14fb602SLionel Sambuc.It Bq Er EMFILE
129f14fb602SLionel SambucToo many descriptors are active.
130f14fb602SLionel Sambuc.It Bq Er ENFILE
131f14fb602SLionel SambucThe system file table is full.
132f14fb602SLionel Sambuc.El
133f14fb602SLionel Sambuc.Pp
134f14fb602SLionel Sambuc.Fn pipe2
135f14fb602SLionel Sambucwill also fail if:
136f14fb602SLionel Sambuc.Bl -tag -width Er
137f14fb602SLionel Sambuc.It Bq Er EINVAL
138f14fb602SLionel Sambuc.Fa flags
139*0a6a1f1dSLionel Sambuccontains an invalid value.
1402fe8fb19SBen Gras.El
1412fe8fb19SBen Gras.Sh SEE ALSO
1422fe8fb19SBen Gras.Xr sh 1 ,
1432fe8fb19SBen Gras.Xr fork 2 ,
1442fe8fb19SBen Gras.Xr read 2 ,
1452fe8fb19SBen Gras.Xr socketpair 2 ,
1462fe8fb19SBen Gras.Xr write 2
1472fe8fb19SBen Gras.Sh STANDARDS
1482fe8fb19SBen GrasThe
1492fe8fb19SBen Gras.Fn pipe
1502fe8fb19SBen Grasfunction conforms to
1512fe8fb19SBen Gras.St -p1003.1-90 .
1522fe8fb19SBen Gras.Sh HISTORY
1532fe8fb19SBen GrasA
1542fe8fb19SBen Gras.Fn pipe
1552fe8fb19SBen Grasfunction call appeared in
1562fe8fb19SBen Gras.At v6 .
157f14fb602SLionel SambucThe
158f14fb602SLionel Sambuc.Fn pipe2
159f14fb602SLionel Sambucfunction is inspired from Linux and appeared in
160f14fb602SLionel Sambuc.Nx 6.0 .
161