1.\" $OpenBSD: pipe.2,v 1.10 2000/12/21 09:24:01 pjanzen Exp $ 2.\" $NetBSD: pipe.2,v 1.6 1995/02/27 12:35:27 cgd Exp $ 3.\" 4.\" Copyright (c) 1980, 1991, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. All advertising materials mentioning features or use of this software 16.\" must display the following acknowledgement: 17.\" This product includes software developed by the University of 18.\" California, Berkeley and its contributors. 19.\" 4. Neither the name of the University nor the names of its contributors 20.\" may be used to endorse or promote products derived from this software 21.\" without specific prior written permission. 22.\" 23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" SUCH DAMAGE. 34.\" 35.\" @(#)pipe.2 8.1 (Berkeley) 6/4/93 36.\" 37.Dd June 4, 1993 38.Dt PIPE 2 39.Os 40.Sh NAME 41.Nm pipe 42.Nd create descriptor pair for interprocess communication 43.Sh SYNOPSIS 44.Fd #include <unistd.h> 45.Ft int 46.Fn pipe "int fildes[2]" 47.Sh DESCRIPTION 48The 49.Fn pipe 50function creates a 51.Em pipe , 52which is an object allowing unidirectional data flow, 53and allocates a pair of file descriptors. 54The first descriptor connects to the 55.Em read end 56of the pipe, 57and the second connects to the 58.Em write end , 59so that data written to 60.Fa fildes[1] 61appears on (i.e., can be read from) 62.Fa fildes[0] . 63This allows the output of one program to be sent to another program: 64the source's standard output is set up to be the write end of the pipe, 65and the sink's standard input is set up to be the read end of the pipe. 66The pipe itself persists until all its associated descriptors are closed. 67.Pp 68A pipe whose read or write end has been closed is considered 69.Em widowed . 70Writing on such a pipe causes the writing process to receive a 71.Dv SIGPIPE 72signal. 73Widowing a pipe is the only way to deliver end-of-file to a reader: 74after the reader consumes any buffered data, reading a widowed pipe 75returns a zero count. 76.Sh RETURN VALUES 77On successful creation of the pipe, zero is returned. 78Otherwise, a value of \-1 is returned and the variable 79.Va errno 80set to indicate the error. 81.Sh ERRORS 82The 83.Fn pipe 84call will fail if: 85.Bl -tag -width Er 86.It Bq Er EMFILE 87Too many descriptors are active. 88.It Bq Er ENFILE 89The system file table is full. 90.It Bq Er EFAULT 91The 92.Fa fildes 93buffer is in an invalid area of the process's address space. 94.El 95.Sh SEE ALSO 96.Xr sh 1 , 97.Xr fork 2 , 98.Xr read 2 , 99.Xr socketpair 2 , 100.Xr write 2 101.Sh STANDARDS 102The 103.Fn pipe 104function conforms to 105.St -p1003.1-88 . 106.Pp 107As an extension, the pipe provided is actually capable of moving 108data bidirectionally. 109This is compatible with SVR4. 110However, this is non-POSIX behaviour which should not be relied on, 111for reasons of portability. 112.Sh HISTORY 113A 114.Fn pipe 115function call appeared in 116.At v6 . 117