1pipe(2) System Calls pipe(2)
2
3
4
6 pipe - create an interprocess channel
7
9 #include <unistd.h>
10
11 int pipe(int fildes[2]);
12
13
15 The pipe() function creates an I/O mechanism called a pipe and returns
16 two file descriptors, fildes[0] and fildes[1]. The files associated
17 with fildes[0] and fildes[1] are streams and are both opened for read‐
18 ing and writing. The O_NDELAY, O_NONBLOCK, and FD_CLOEXEC flags are
19 cleared on both file descriptors. The fcntl(2) function can be used to
20 set these flags.
21
22
23 A read from fildes[0] accesses the data written to fildes[1] on a
24 first-in-first-out (FIFO) basis and a read from fildes[1] accesses the
25 data written to fildes[0] also on a FIFO basis.
26
27
28 Upon successful completion pipe() marks for update the st_atime,
29 st_ctime, and st_mtime fields of the pipe.
30
32 Upon successful completion, 0 is returned. Otherwise, −1 is returned
33 and errno is set to indicate the error.
34
36 The pipe() function will fail if:
37
38 EMFILE More than {OPEN_MAX} file descriptors are already in use by
39 this process.
40
41
42 ENFILE The number of simultaneously open files in the system would
43 exceed a system-imposed limit.
44
45
47 See attributes(5) for descriptions of the following attributes:
48
49
50
51
52 ┌─────────────────────────────┬─────────────────────────────┐
53 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
54 ├─────────────────────────────┼─────────────────────────────┤
55 │Interface Stability │Standard │
56 ├─────────────────────────────┼─────────────────────────────┤
57 │MT-Level │Async-Signal-Safe │
58 └─────────────────────────────┴─────────────────────────────┘
59
61 sh(1), fcntl(2), fstat(2), getmsg(2), poll(2), putmsg(2), read(2),
62 write(2), attributes(5), standards(5), streamio(7I)
63
65 Since a pipe is bi-directional, there are two separate flows of data.
66 Therefore, the size (st_size) returned by a call to fstat(2) with argu‐
67 ment fildes[0] or fildes[1] is the number of bytes available for read‐
68 ing from fildes[0] or fildes[1] respectively. Previously, the size
69 (st_size) returned by a call to fstat() with argument fildes[1] (the
70 write-end) was the number of bytes available for reading from fildes[0]
71 (the read-end).
72
73
74
75SunOS 5.11 23 Apr 2002 pipe(2)