BSD 4_2 development
[unix-history] / usr / man / man2 / pipe.2
CommitLineData
ea709105
C
1.TH PIPE 2 "12 February 1983"
2.UC 4
3.SH NAME
4pipe \- create an interprocess communication channel
5.SH SYNOPSIS
6.nf
7.ft B
8pipe(fildes)
9int fildes[2];
10.fi
11.ft R
12.SH DESCRIPTION
13The
14.I pipe
15system call
16creates an I/O mechanism called a pipe.
17The file descriptors returned can
18be used in read and write operations.
19When the pipe is written using the descriptor
20.IR fildes [1]
21up to 4096 bytes of data are buffered
22before the writing process is suspended.
23A read using the descriptor
24.IR fildes [0]
25will pick up the data.
26.PP
27It is assumed that after the
28pipe has been set up,
29two (or more)
30cooperating processes
31(created by subsequent
32.I fork
33calls)
34will pass data through the
35pipe with
36.I read
37and
38.I write
39calls.
40.PP
41The shell has a syntax
42to set up a linear array of processes
43connected by pipes.
44.PP
45Read calls on an empty
46pipe (no buffered data) with only one end
47(all write file descriptors closed)
48returns an end-of-file.
49.PP
50Pipes are really a special case of the
51.IR socketpair (2)
52call and, in fact, are implemented as such in the system.
53.PP
54A signal is generated if a write on a pipe with only one end is attempted.
55.SH "RETURN VALUE
56The function value zero is returned if the
57pipe was created; \-1 if an error occurred.
58.SH ERRORS
59The \fIpipe\fP call will fail if:
60.TP 15
61[EMFILE]
62Too many descriptors are active.
63.TP 15
64[EFAULT]
65The \fIfildes\fP buffer is in an invalid area of the process's address
66space.
67.SH "SEE ALSO"
68sh(1), read(2), write(2), fork(2), socketpair(2)
69.SH BUGS
70Should more than 4096 bytes be necessary in any
71pipe among a loop of processes, deadlock will occur.