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