#include <libc.h>
int pipe(int fd[2])
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. The bytes placed on a pipe by one 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.
The number of bytes available to a read (2) is reported in the Length field returned by fstat or dirfstat on a pipe (see stat (2)).
When all the data has been read from a pipe and the writer has closed the pipe or exited, read (2) will return 0 bytes. Writes to a pipe with no reader will generate a note "sys: write on closed pipe" .
When a read from a pipe returns 0 bytes, it usually means end of file but is indistinguishable from reading the result of an explicit write of zero bytes.