2004-04-10 18:53:55 +00:00
|
|
|
.TH PIPE 3
|
|
|
|
.SH NAME
|
|
|
|
pipe \- create an interprocess channel
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.B #include <u.h>
|
|
|
|
.br
|
|
|
|
.B #include <libc.h>
|
|
|
|
.PP
|
|
|
|
.B
|
|
|
|
int pipe(int fd[2])
|
|
|
|
.SH DESCRIPTION
|
|
|
|
.I Pipe
|
|
|
|
creates a buffered channel for interprocess I/O communication.
|
|
|
|
Two file descriptors are returned in
|
|
|
|
.IR fd .
|
|
|
|
Data written to
|
|
|
|
.B fd[1]
|
|
|
|
is available for reading from
|
|
|
|
.B fd[0]
|
|
|
|
and data written to
|
|
|
|
.B fd[0]
|
|
|
|
is available for reading from
|
|
|
|
.BR fd[1] .
|
|
|
|
.PP
|
|
|
|
After the pipe has been established,
|
|
|
|
cooperating processes
|
|
|
|
created by subsequent
|
2020-08-16 00:07:38 +00:00
|
|
|
.MR fork (2)
|
2004-04-10 18:53:55 +00:00
|
|
|
calls may pass data through the
|
|
|
|
pipe with
|
|
|
|
.I read
|
|
|
|
and
|
|
|
|
.I write
|
|
|
|
calls.
|
2005-01-03 06:40:20 +00:00
|
|
|
.\" The bytes placed on a pipe
|
|
|
|
.\" by one
|
|
|
|
.\" .I write
|
|
|
|
.\" are contiguous even if many processes are writing.
|
|
|
|
.\" Write boundaries are preserved: each read terminates
|
|
|
|
.\" when the read buffer is full or after reading the last byte
|
|
|
|
.\" of a write, whichever comes first.
|
|
|
|
.\" .PP
|
|
|
|
.\" The number of bytes available to a
|
|
|
|
.\" .IR read (3)
|
|
|
|
.\" is reported
|
|
|
|
.\" in the
|
|
|
|
.\" .B Length
|
|
|
|
.\" field returned by
|
|
|
|
.\" .I fstat
|
|
|
|
.\" or
|
|
|
|
.\" .I dirfstat
|
|
|
|
.\" on a pipe (see
|
|
|
|
.\" .IR stat (3)).
|
2004-04-10 18:53:55 +00:00
|
|
|
.PP
|
|
|
|
When all the data has been read from a pipe and the writer has closed the pipe or exited,
|
2020-08-16 00:07:38 +00:00
|
|
|
.MR read (3)
|
2004-04-10 18:53:55 +00:00
|
|
|
will return 0 bytes. Writes to a pipe with no reader will generate a note
|
|
|
|
.BR "sys: write on closed pipe" .
|
|
|
|
.SH SOURCE
|
2005-01-11 17:37:33 +00:00
|
|
|
.B \*9/src/lib9/pipe.c
|
2004-04-10 18:53:55 +00:00
|
|
|
.SH SEE ALSO
|
2020-08-16 00:07:38 +00:00
|
|
|
.MR intro (3) ,
|
|
|
|
.MR read (3)
|
2004-04-10 18:53:55 +00:00
|
|
|
.SH DIAGNOSTICS
|
|
|
|
Sets
|
|
|
|
.IR errstr .
|
|
|
|
.SH BUGS
|
|
|
|
If a read or a write of a pipe is interrupted, some unknown
|
|
|
|
number of bytes may have been transferred.
|
2005-01-03 06:40:20 +00:00
|
|
|
.PP
|
|
|
|
.I Pipe
|
|
|
|
is a macro defined as
|
|
|
|
.I p9pipe
|
|
|
|
to avoid name conflicts with Unix's
|
|
|
|
.I pipe
|
|
|
|
system call.
|
|
|
|
.PP
|
|
|
|
Unix pipes are not guaranteed to be bidirectional.
|
|
|
|
In order to ensure a bidirectional channel,
|
|
|
|
.I p9pipe
|
|
|
|
creates Unix domain sockets via the
|
2020-08-16 00:07:38 +00:00
|
|
|
.MR socketpair (2)
|
2005-01-03 06:40:20 +00:00
|
|
|
instead of Unix pipes.
|
|
|
|
.PP
|
|
|
|
The implementation of pipes as Unix domain sockets
|
|
|
|
causes problems with some Unix implementations of
|
|
|
|
.BR /dev/fd ,
|
|
|
|
Unix's dup device. If a Unix domain socket is open as file
|
|
|
|
descriptor 0, some implementations disallow the opening of
|
|
|
|
.BR /dev/fd/0 ;
|
|
|
|
instead one must
|
2020-08-16 00:07:38 +00:00
|
|
|
.MR connect (2)
|
2005-01-03 06:40:20 +00:00
|
|
|
to it.
|
|
|
|
If this functionality is important
|
|
|
|
(as it is for
|
2020-08-16 00:07:38 +00:00
|
|
|
.MR rc (1) ),
|
2005-01-03 06:40:20 +00:00
|
|
|
one must
|
|
|
|
.B #undef
|
|
|
|
.B pipe
|
|
|
|
and fall back on the (possibly unidirectional) Unix pipes.
|