How unix pipes work?
Pipe buffer wraps around.
a full buffer
(nwrite == nread+PIPESIZE)
an empty buffer
(nwrite == nread)
Pipewrite
wakes up reader if buffer is full, or written is down.Piperead
sleep if no more data. Or read data from pipe, copy out to address. Then wake up the write channel.
Flow
TODO
Add more code.
A few open questions:
In
piperead
, why we wake up write first, then releasepi->lock
?Why
piperead
does not go back to sleep after reading? Why there is no loop forpiperead
? Or is there an outside loop?
Last updated