[Haskell-cafe] Re: process
bos at serpentine.com
Fri Feb 23 13:37:46 EST 2007
Bryan O'Sullivan wrote:
> Just because *your* end of each pipe is a line-buffered file handle has
> no bearing on the *other* process's management of its pair of endpoints.
> For example, on a Unix-like system, the other process's stdio will
> block-buffer stdin and stdout by default if it finds that they're not
> attached to tty-like file descriptors.
In case the implications of this aren't clear, let me expand a little.
You've got a line-buffered stdout. You write "1+1\n", which sends 4
bytes to the other process.
It's got a block-buffered stdin, so it's going to sit in its first read
until it receives 512 bytes (or whatever the buffer size is) from you.
And an oversized violin, you have a deadlock!
The converse bites you, too. You want to read a line from the other
process. It writes "1+1\n" to you, but its stdio buffers up the 4 bytes
because it hasn't reached the 512-byte watermark. It then tries to read
from you, but you're still blocked trying to read the first line (that
it hasn't actually sent) from it. Deadlock.
More information about the Haskell-Cafe