Is it safe to call getProcessExitCode more than once?

Glynn Clements glynn at
Thu Oct 28 02:00:08 EDT 2004

David Brown wrote:

> >  > Both [waitForProcess and getProcessExitCode] will throw
> >  > an exception if the process terminated on a signal.
> > 
> > So if I terminate a process manually, I'll have to wait for
> > the ExitCode to avoid a zombie process, and waiting for the
> > ExitCode invariably throws an exception.
> It's just the way that Unix process management works.  I guess you have to
> catch the exception to handle it well.  This is part of the aspect that
> makes writing shells so complicated.

I think that Peter was referring primarily to the fact that the
Haskell interface to waitpid() throws an exception if the process
terminated due to a signal, not the fact that you have to "reap"
children to prevent the accumulation of zombies.

The C interface is that waitpid() (and similar) return a status code;
you can then use the macros from <sys/wait.h> to determine whether the
process terminated normally (e.g. via exit()) or abnormally (due to a
fatal signal), and to obtain either the exit code or the signal number
as appropriate.

The Haskell interface oversimplifies matters, making it easier to get
the exit code in the case of normal termination, but complicating the
handling of abnormal termination.

Glynn Clements <glynn at>

More information about the Glasgow-haskell-users mailing list