Proposal: System.Timeout module for base (Trac #980)

Bayley, Alistair Alistair_Bayley at
Thu Mar 1 06:04:38 EST 2007

> From: libraries-bounces at 
> [mailto:libraries-bounces at] On Behalf Of Johannes Waldmann
> would this combinator help solve the following problem:
> I have two (or more) threads (created by forkIO)
> and each does an external ( System.Cmd.system ) call.
> When the first of these returns, the others should be killed.
> (when I try to kill the Haskell RTS threads,
> the external programs still seem to continue).

That doesn't seem possible with System.Cmd. You may want to look at
System.Process instead, because that has a terminateProcess function.

You could (for each thread):
  1. start process with runCommand or runProcess
  2. call waitForProcess; when it completes, kill the other thread(s)
  3. wrap step 2 in a catch; in the handler, call terminateProcess, then
rethrow (this should catch the AsyncException).


proc <- runCommand "blah blah"
  ( do
    ec <- waitForProcess proc
    killThread otherThread(s)
    return ec  -- do you care about the exit code?
  (\e -> do
    terminateProcess proc
    throwIO e

I haven't tried this - any better ideas?

Confidentiality Note: The information contained in this message,
and any attachments, may contain confidential and/or privileged
material. It is intended solely for the person(s) or entity to
which it is addressed. Any review, retransmission, dissemination,
or taking of any action in reliance upon this information by
persons or entities other than the intended recipient(s) is
prohibited. If you received this in error, please contact the
sender and delete the material from any computer.

More information about the Libraries mailing list