how to terminate an external program after timeout?

Simon Marlow marlowsd at
Mon Sep 13 04:37:07 EDT 2010

On 09/09/2010 17:18, Christian Maeder wrote:
> David Peixotto schrieb:
>> On Sep 9, 2010, at 6:37 AM, Simon Marlow wrote:
>>> On 09/09/2010 10:39, Christian Maeder wrote:
>>>> Christian Maeder schrieb:
>>>>> Hi,
>>>>> we call from our haskell application the metis prover via
>>>>>   System.Process.readProcessWithExitCode "metis" filename ""
>>>>> However, we are not able to get rid of this process if metis does not
>>>>> terminate by itself. In particular, wrapping this call into a
>>>>> System.Timeout.timeout does not work.
>>>> timeout works so far as it is possible to start another action, but the
>>>> continuing metis process still blocks the whole system.
>>>> C.
>>>>> Any suggestions how we should handle this ideally portably but first of
>>>>> all under unix. (ghc-6.12.3)
>>> Take a look at the timeout program in GHC's test suite:
> This looks pretty complicated. Did no one else needed this? Isn't it
> easier to put the application into a wrapper script and call the script
> from haskell?

It is pretty complicated, because properly wrapping a process in a 
timeout is a complicated task.  You have to:

  - kill not just the process you started, but any children it started

  - catch ^C, and pass it to the child process(es)

  - if the child process died with a signal, arrange that the wrapper
    dies with the same signal, so that the parent can see what happened

  - try to kill nicely, giving them a chance to clean up, but kill
    forcefully if that doesn't work.

It would be a good idea to wrap this up and put it on Hackage, in fact.


More information about the Glasgow-haskell-users mailing list