System.Process bugs on Unix

Simon Marlow simonmarhaskell at
Mon Apr 2 05:13:33 EDT 2007

Bryan O'Sullivan wrote:
> Simon Marlow wrote:
>> I'm sure, yes.  The non-blocking flag is part of the "open file 
>> description" (see [1], [2]), not the file descriptor.
> Ah, yes indeed.  I had misunderstood what runProcess was trying to do. 
> Given that, the patch I believed would help was not, in fact, going to 
> do so.
> If there's a way to work around this behaviour, it's not obvious to me. 
>  Had you any thoughts in mind?

We use O_NONBLOCK to do multithreaded I/O with our lightweight threads.  If 
you're prepared to use OS threads, then you don't need O_NONBLOCK, you can just 
make a non-blocking foreign call to do the I/O: e.g foreign import safe "read", 
this makes the call in a separate OS thread, so other Haskell threads aren't 
blocked.  Only the threaded RTS supports OS threads, though.

The idea in my patch (not my idea, I think it's been used elsewhere) is to allow 
both kinds of FDs: non-blocking I/O for FDs that we are sure are local to the 
current process, and ordinary blocking I/O with OS threads for FDs that might be 
shared with another process.  In the non-threaded RTS you have two options: 
continue to use O_NONBLOCK and keep the tee bug, or use blocking I/O for the 
standard FDs (all other threads will be blocked while you do I/O on a std FD).


More information about the Libraries mailing list