Commit | Line | Data |
---|---|---|
931b8415 CL |
1 | .\" Copyright (c) 1980, 1991 Regents of the University of California. |
2 | .\" All rights reserved. | |
c15b236d | 3 | .\" |
931b8415 | 4 | .\" %sccs.include.redist.man% |
c15b236d | 5 | .\" |
931b8415 CL |
6 | .\" @(#)pipe.2 6.3 (Berkeley) %G% |
7 | .\" | |
8 | .Dd | |
9 | .Dt PIPE 2 | |
10 | .Os BSD 4 | |
11 | .Sh NAME | |
12 | .Nm pipe | |
13 | .Nd create descriptor pair for interprocess communication | |
14 | .Sh SYNOPSIS | |
15 | .Fd #include <unistd.h> | |
16 | .Ft int | |
17 | .Fn pipe "int *fildes" | |
18 | .Sh DESCRIPTION | |
c15b236d | 19 | The |
931b8415 CL |
20 | .Fn pipe |
21 | function | |
22 | creates a | |
23 | .Em pipe , | |
24 | which is an object allowing | |
25 | unidirectional data flow, | |
26 | and allocates a pair of file descriptors. | |
27 | The first descriptor connects to the | |
28 | .Em read end | |
29 | of the pipe, | |
30 | and the second connects to the | |
31 | .Em write end , | |
32 | so that data written to | |
33 | .Fa fildes[1] | |
34 | appears on (i.e., can be read from) | |
35 | .Fa fildes[0] . | |
36 | This allows the output of one program to be | |
37 | sent | |
38 | to another program: | |
39 | the source's standard output is set up to be | |
40 | the write end of the pipe, | |
41 | and the sink's standard input is set up to be | |
42 | the read end of the pipe. | |
43 | The pipe itself persists until all its associated descriptors are | |
44 | closed. | |
45 | .Pp | |
46 | A pipe whose read or write end has been closed is considered | |
47 | .Em widowed . | |
48 | Writing on such a pipe causes the writing process to receive | |
49 | a | |
50 | .Dv SIGPIPE | |
51 | signal. | |
52 | Widowing a pipe is the only way to deliver end-of-file to a reader: | |
53 | after the reader consumes any buffered data, reading a widowed pipe | |
54 | returns a zero count. | |
55 | .Pp | |
0bbf2c7d | 56 | Pipes are really a special case of the |
931b8415 | 57 | .Xr socketpair 2 |
0bbf2c7d | 58 | call and, in fact, are implemented as such in the system. |
931b8415 CL |
59 | .Sh RETURN VALUES |
60 | On successful creation of the pipe, zero is returned. Otherwise, | |
61 | a value of -1 is returned and the variable | |
62 | .Va errno | |
63 | set to indicate the | |
64 | error. | |
65 | .Sh ERRORS | |
66 | The | |
67 | .Fn pipe | |
68 | call will fail if: | |
69 | .Bl -tag -width [EMFILE] | |
70 | .It Bq Er EMFILE | |
0bbf2c7d | 71 | Too many descriptors are active. |
931b8415 | 72 | .It Bq Er ENFILE |
fd690c8b | 73 | The system file table is full. |
931b8415 CL |
74 | .It Bq Er EFAULT |
75 | The | |
76 | .Fa fildes | |
77 | buffer is in an invalid area of the process's address | |
0bbf2c7d | 78 | space. |
931b8415 CL |
79 | .El |
80 | .Sh SEE ALSO | |
81 | .Xr sh 1 , | |
82 | .Xr read 2 , | |
83 | .Xr write 2 , | |
84 | .Xr fork 2 , | |
85 | .Xr socketpair 2 | |
86 | .Sh HISTORY | |
87 | A | |
88 | .Nm | |
89 | function call appeared in Version 6 AT&T UNIX. |