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