ghci and ghc -threaded broken with pipes & forking

John Goerzen jgoerzen at
Fri Mar 2 19:07:26 EST 2007

On 2007-03-02, Simon Marlow <simonmarhaskell at> wrote:

> Regarding your shell: I would suggest trying forkIO for the Haskell "processes" 
> (not forkOS unless for some reason you really need another OS thread).  However, 
>   I can imagine that it might be hard to implement job control and signal 
> handling in that system.  You could also consider using 
> System.Process.runInteractiveProcess, for portability.

Thinking about forkIO seems that it could be fairly complex to just drop
in.  The problem lies around file descriptors.  When you fork off a new
process, and then close file descriptors in the parent, they stay open
in the child, and vice versa.  Proper management of file descriptors is
a critical part of a shell, and it's vital to close the proper set of
FDs at the proper time in the parent and the child, or else bad things
like pipes never closing could easily lead to deadlock.

Of course, it is possible to work around this, but I fear that it could
make the program very complex.

-- John

More information about the Glasgow-haskell-users mailing list