74 lines · 1.5 KB · Text
RawDownload
.TH PIPE 2.SH NAMEpipe \- create an interprocess channel.SH SYNOPSIS.B #include <u.h>.br.B #include <libc.h>.PP.Bint pipe(int fd[2]).SH DESCRIPTION.I Pipecreates 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] ..PPAfter the pipe has been established,cooperating processescreated by subsequent.IR fork (2)calls may pass data through thepipe with.I readand.I writecalls.The bytes placed on a pipeby one .I writeare contiguous even if many processes are writing.Write boundaries are preserved: each read terminateswhen the read buffer is full or after reading the last byteof a write, whichever comes first..PPThe number of bytes available to a.IR read (2)is reportedin the.B Lengthfield returned by.I fstator.I dirfstaton a pipe (see.IR stat (2))..PPWhen all the data has been read from a pipe and the writer has closed the pipe or exited,.IR read (2)will return 0 bytes.  Writes to a pipe with no reader will generate a note.BR "sys: write on closed pipe" ..SH SOURCE.B /sys/src/libc/9syscall.SH SEE ALSO.IR intro (2),.IR read (2),.IR pipe (3).SH DIAGNOSTICSSets.IR errstr ..SH BUGSIf a read or a write of a pipe is interrupted, some unknownnumber of bytes may have been transferred..brWhen a read from a pipe returns 0 bytes, it usually means end of filebut is indistinguishable from reading the result of an explicitwrite of zero bytes.