[Haskell-cafe] Re: exitFailure under forkProcess

John Goerzen jgoerzen at complete.org
Tue Oct 26 20:56:12 EDT 2004

On 2004-10-26, Peter Simons <simons at cryp.to> wrote:
> John Goerzen writes:
> > (progname): forkProcess: uncaught exception
> Quoting from the documentation:
>   forkProcess :: IO () -> IO ProcessID
>   [...] On success, forkProcess returns the child's
>   ProcessID to the parent process; in case of an error, an
>   exception is thrown.
> What I assume is happening is this: The child terminates
> _right away_, with a non-success error code, no less. And my
> guess is that forkProcess interprets this as the /fork/
> having failed and throws an exception.

If you follow this a little bit, you'll find that forkProcess is *NOT*
throwing the exception that is being reported here.  The message is
being printed by the RTS of the child process.  No exception is thrown
in the parent.  (Believe me, I've tried to catch it!)

I thought about that a bit, and realized that is the only way it could
be; there's no way an exception could propogate from a child forked
process to the parent.

In my particular case, in my child process, the problem was occuring
when I detected an exec failure and wnated to terminate with an error
code for the parent to catch.  I called dupTo a few times in the child
before that, so while it failed fast, it was doing things.

> The following program, for example, works fine:
>> import System.Exit
>> import System.Posix.Process
>> import Control.Concurrent
>> main = forkProcess (threadDelay (10*1000000) >> exitFailure)

I have no idea why that would be.  Sigh.

> Peter

John Goerzen
Author, Foundations of Python Network Programming

More information about the Haskell-Cafe mailing list