PIPE(3)                                                   PIPE(3)

     NAME
          pipe - two-way interprocess communication

     SYNOPSIS
          bind '#|'dir
          dir/data
          dir/data1

     DESCRIPTION
          A pipe provides a mechanism for interprocess I/O by reading
          and writing file descriptors (see sys-read(2)). An
          attach(5), typically via sys-pipe(2) or sys-bind(2), allo-
          cates 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 usu-
          ally 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 inter-
          nal queues (see 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.  Writ-
          ers to pipe interfaces on remotely mounted portions of the
          namespace have their guarantee of atomicity lowered to
          Sys->ATOMICIO bytes by 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 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 sub-
          sequent 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.

     Page 1                       Plan 9             (printed 3/28/24)

     PIPE(3)                                                   PIPE(3)

     SOURCE
          /emu/port/devpipe.c
          /os/port/devpipe.c

     SEE ALSO
          sys-file2chan(2), sys-pipe(2)

     DIAGNOSTICS
          Writes to a closed pipe generate an exception `write on
          closed pipe'.  Persistently reading a closed pipe after
          reading end-of-file will result in a read error.

     Page 2                       Plan 9             (printed 3/28/24)