| PIPE(3) | PIPE(3)
| NAME
| pipe – create an interprocess channel
SYNOPSIS
| `#include <u.h> #include <libc.h>
` `int pipe(int fd[2])`
DESCRIPTION
| Pipe creates a buffered channel for interprocess I/O communication. Two file descriptors are returned in fd. Data written to `fd[1]` is available for reading from `fd[0]` and data written to `fd[0]` is available for reading from `fd[1]`.
After the pipe has been established, cooperating processes created by subsequent fork(2) calls may pass data through the pipe with read and write calls.
When all the data has been read from a pipe and the writer has closed the pipe or exited, read(3) will return 0 bytes. Writes to a pipe with no reader will generate a note `sys: write on closed pipe`.
SOURCE
| `/build/plan9port/pkg/plan9port/usr/local/plan9port/src/lib9/pipe.c`
SEE ALSO
| intro(3), read(3)
DIAGNOSTICS
| Sets errstr.
BUGS
| If a read or a write of a pipe is interrupted, some unknown number of bytes may have been transferred.
Pipe is a macro defined as p9pipe to avoid name conflicts with Unix’s pipe system call.
Unix pipes are not guaranteed to be bidirectional. In order to ensure a bidirectional channel, p9pipe creates Unix domain sockets via the socketpair(2) instead of Unix pipes.
The implementation of pipes as Unix domain sockets causes problems with some Unix implementations of `/dev/fd`, Unix’s dup device. If a Unix domain socket is open as file descriptor 0, some implementations disallow the opening of `/dev/fd/0`; instead one must connect(2) to it. If this functionality is important (as it is for rc(1)), one must `#undef pipe` and fall back on the (possibly unidirectional) Unix pipes.