shithub: 9ferno

ref: b502a62da2ec6058923db94f87ecc2d29db2fa77
dir: /man/3/pipe/

View raw version
pipe \- two-way interprocess communication
.BI "bind '#|'" dir
.IB dir /data
.IB dir /data1
A pipe provides a mechanism for interprocess I/O by
reading and writing file descriptors (see
.IR sys-read (2)).
.IR attach (5),
typically via
.IR sys-pipe (2)
.IR sys-bind (2),
allocates two files that are cross-connected:
data written to one can be read back from the other, in the same order.
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.
In particular, a write of zero bytes will result in a zero-length read,
which is usually interpreted by readers as end-of-file, but could be used
to delimit the data stream for other purposes.
Written data is buffered by the kernel and stored on internal queues
.IR qio (10.2)).
The maximum block size is 128k bytes;
larger writes will be split across several blocks, which are queued separately.
Each read will return data from at most one block.
Concurrent writers are therefore guaranteed that their data will not be interleaved
with data from other writers (ie, will be written atomically) only when
each write is less than the maximum buffer size.
Writers to pipe interfaces on remotely mounted portions of the namespace have their guarantee of atomicity lowered to
bytes by
.IR mnt (3).
The system mediates between producer and consumer.
Writers will block when buffered data reaches a high-water mark, currently 32k bytes,
until a reader has reduced it by half.
The length returned by
.IR sys-stat (2)
on each name
gives the number of bytes waiting to be read on the corresponding end of the pipe.
When all file descriptors on
one side of the pipe have been closed, and after any remaining data has
been read,
a reader on the other side sees end-of-file (count of zero) on a subsequent read.
Once both ends are closed, the pipe can be reused.
A pipe persists until it is unmounted and no processes have either end open.
.B /emu/port/devpipe.c
.B /os/port/devpipe.c
.IR sys-file2chan (2),
.IR sys-pipe (2)
Writes to a closed pipe generate an exception
.RB ` "write on closed pipe" '.
Persistently reading a closed pipe after reading end-of-file
will result in a read error.