1*61183Sbostic.\" Copyright (c) 1980, 1991, 1993 2*61183Sbostic.\" The Regents of the University of California. All rights reserved. 320086Smckusick.\" 447208Scael.\" %sccs.include.redist.man% 520086Smckusick.\" 6*61183Sbostic.\" @(#)pipe.2 8.1 (Berkeley) 06/04/93 747208Scael.\" 847208Scael.Dd 947208Scael.Dt PIPE 2 1047208Scael.Os BSD 4 1147208Scael.Sh NAME 1247208Scael.Nm pipe 1347208Scael.Nd create descriptor pair for interprocess communication 1447208Scael.Sh SYNOPSIS 1547208Scael.Fd #include <unistd.h> 1647208Scael.Ft int 1747208Scael.Fn pipe "int *fildes" 1847208Scael.Sh DESCRIPTION 1920086SmckusickThe 2047208Scael.Fn pipe 2147208Scaelfunction 2247208Scaelcreates a 2347208Scael.Em pipe , 2447208Scaelwhich is an object allowing 2547208Scaelunidirectional data flow, 2647208Scaeland allocates a pair of file descriptors. 2747208ScaelThe first descriptor connects to the 2847208Scael.Em read end 2947208Scaelof the pipe, 3047208Scaeland the second connects to the 3147208Scael.Em write end , 3247208Scaelso that data written to 3347208Scael.Fa fildes[1] 3447208Scaelappears on (i.e., can be read from) 3547208Scael.Fa fildes[0] . 3647208ScaelThis allows the output of one program to be 3747208Scaelsent 3847208Scaelto another program: 3947208Scaelthe source's standard output is set up to be 4047208Scaelthe write end of the pipe, 4147208Scaeland the sink's standard input is set up to be 4247208Scaelthe read end of the pipe. 4347208ScaelThe pipe itself persists until all its associated descriptors are 4447208Scaelclosed. 4547208Scael.Pp 4647208ScaelA pipe whose read or write end has been closed is considered 4747208Scael.Em widowed . 4847208ScaelWriting on such a pipe causes the writing process to receive 4947208Scaela 5047208Scael.Dv SIGPIPE 5147208Scaelsignal. 5247208ScaelWidowing a pipe is the only way to deliver end-of-file to a reader: 5347208Scaelafter the reader consumes any buffered data, reading a widowed pipe 5447208Scaelreturns a zero count. 5547208Scael.Pp 5620087SmckusickPipes are really a special case of the 5747208Scael.Xr socketpair 2 5820087Smckusickcall and, in fact, are implemented as such in the system. 5947208Scael.Sh RETURN VALUES 6047208ScaelOn successful creation of the pipe, zero is returned. Otherwise, 6147208Scaela value of -1 is returned and the variable 6247208Scael.Va errno 6347208Scaelset to indicate the 6447208Scaelerror. 6547208Scael.Sh ERRORS 6647208ScaelThe 6747208Scael.Fn pipe 6847208Scaelcall will fail if: 6947208Scael.Bl -tag -width [EMFILE] 7047208Scael.It Bq Er EMFILE 7120087SmckusickToo many descriptors are active. 7247208Scael.It Bq Er ENFILE 7324439SmckusickThe system file table is full. 7447208Scael.It Bq Er EFAULT 7547208ScaelThe 7647208Scael.Fa fildes 7747208Scaelbuffer is in an invalid area of the process's address 7820087Smckusickspace. 7947208Scael.El 8047208Scael.Sh SEE ALSO 8147208Scael.Xr sh 1 , 8247208Scael.Xr read 2 , 8347208Scael.Xr write 2 , 8447208Scael.Xr fork 2 , 8547208Scael.Xr socketpair 2 8647208Scael.Sh HISTORY 8747208ScaelA 8847208Scael.Nm 8947208Scaelfunction call appeared in Version 6 AT&T UNIX. 90