blob: 10decb696e264969df45c65e6ddafc4ab020119d [file] [log] [blame]
rsccfa37a72004-04-10 18:53:55 +00001.TH PIPE 3
2.SH NAME
3pipe \- create an interprocess channel
4.SH SYNOPSIS
5.B #include <u.h>
6.br
7.B #include <libc.h>
8.PP
9.B
10int pipe(int fd[2])
11.SH DESCRIPTION
12.I Pipe
13creates a buffered channel for interprocess I/O communication.
14Two file descriptors are returned in
15.IR fd .
16Data written to
17.B fd[1]
18is available for reading from
19.B fd[0]
20and data written to
21.B fd[0]
22is available for reading from
23.BR fd[1] .
24.PP
25After the pipe has been established,
26cooperating processes
27created by subsequent
rsc058b0112005-01-03 06:40:20 +000028.IR fork (2)
rsccfa37a72004-04-10 18:53:55 +000029calls may pass data through the
30pipe with
31.I read
32and
33.I write
34calls.
rsc058b0112005-01-03 06:40:20 +000035.\" The bytes placed on a pipe
36.\" by one
37.\" .I write
38.\" are contiguous even if many processes are writing.
39.\" Write boundaries are preserved: each read terminates
40.\" when the read buffer is full or after reading the last byte
41.\" of a write, whichever comes first.
42.\" .PP
43.\" The number of bytes available to a
44.\" .IR read (3)
45.\" is reported
46.\" in the
47.\" .B Length
48.\" field returned by
49.\" .I fstat
50.\" or
51.\" .I dirfstat
52.\" on a pipe (see
53.\" .IR stat (3)).
rsccfa37a72004-04-10 18:53:55 +000054.PP
55When all the data has been read from a pipe and the writer has closed the pipe or exited,
rscbf8a59f2004-04-11 03:42:27 +000056.IR read (3)
rsccfa37a72004-04-10 18:53:55 +000057will return 0 bytes. Writes to a pipe with no reader will generate a note
58.BR "sys: write on closed pipe" .
59.SH SOURCE
rscc3674de2005-01-11 17:37:33 +000060.B \*9/src/lib9/pipe.c
rsccfa37a72004-04-10 18:53:55 +000061.SH SEE ALSO
rscbf8a59f2004-04-11 03:42:27 +000062.IR intro (3),
rsc058b0112005-01-03 06:40:20 +000063.IR read (3)
rsccfa37a72004-04-10 18:53:55 +000064.SH DIAGNOSTICS
65Sets
66.IR errstr .
67.SH BUGS
68If a read or a write of a pipe is interrupted, some unknown
69number of bytes may have been transferred.
rsc058b0112005-01-03 06:40:20 +000070.PP
71.I Pipe
72is a macro defined as
73.I p9pipe
74to avoid name conflicts with Unix's
75.I pipe
76system call.
77.PP
78Unix pipes are not guaranteed to be bidirectional.
79In order to ensure a bidirectional channel,
80.I p9pipe
81creates Unix domain sockets via the
82.IR socketpair (2)
83instead of Unix pipes.
84.PP
85The implementation of pipes as Unix domain sockets
86causes problems with some Unix implementations of
87.BR /dev/fd ,
88Unix's dup device. If a Unix domain socket is open as file
89descriptor 0, some implementations disallow the opening of
90.BR /dev/fd/0 ;
91instead one must
92.IR connect (2)
93to it.
94If this functionality is important
95(as it is for
96.IR rc (1)),
97one must
98.B #undef
99.B pipe
100and fall back on the (possibly unidirectional) Unix pipes.