how to terminate an external program after timeout?

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. Any suggestions how we should handle this ideally portably but first of all under unix. (ghc-6.12.3) Thanks Christian

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)
Thanks Christian

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: http://darcs.haskell.org/testsuite/timeout/timeout.hs Cheers, Simon

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:
In case it's not obvious, I believe this has to be compiled with -threaded to get the desired behavior. -David
Cheers, Simon _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

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?
In case it's not obvious, I believe this has to be compiled with -threaded to get the desired behavior.
-David
Yes, we do use -threaded. Christian

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. Cheers, Simon

A possible cute solution would be to ulimit the processes permitted cpu time. Cheers, Edward

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 9/9/10 05:35 , Christian Maeder wrote:
System.Process.readProcessWithExitCode "metis" filename ""
If all else fails, there's: sh -c '(sleep 120; kill -TERM $$ >/dev/null 2>&1) & exec metis' which makes the shell deal with timeouts for you. (Adjust sleep time and kill signal as needed.) - -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkyJOIUACgkQIn7hlCsL25VzdwCfcFW/LHTRslit2P4en/o3V88j VEcAnjTB6Dzhpc74TmIvvTUwXwENhDz/ =8ROO -----END PGP SIGNATURE-----

Brandon S Allbery KF8NH schrieb:
On 9/9/10 05:35 , Christian Maeder wrote:
System.Process.readProcessWithExitCode "metis" filename ""
If all else fails, there's:
sh -c '(sleep 120; kill -TERM $$ >/dev/null 2>&1) & exec metis'
Yes, I've considered something like this, too. It does not give metis a chance to terminate earlier, does it? I've found: perl -e 'alarm shift @ARGV; exec @ARGV' 120 metis filename (metis is big already, so the additional perl call can be disregarded.) (In case someone wants to rewrite System.Timeout.timeout I would also suggest to return the output produced until the timeout occurs.) Cheers Christian

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 9/10/10 04:59 , Christian Maeder wrote:
Brandon S Allbery KF8NH schrieb:
On 9/9/10 05:35 , Christian Maeder wrote:
System.Process.readProcessWithExitCode "metis" filename ""
If all else fails, there's:
sh -c '(sleep 120; kill -TERM $$ >/dev/null 2>&1) & exec metis'
Yes, I've considered something like this, too. It does not give metis a chance to terminate earlier, does it?
If metis exits, the backgrounded sleep will keep going, the kill will silently fail, in effect that can be ignored. It would be possible to set up something that nuked the background sleep but then getting the full exit status of metis (if needed; i.e. signals) is complex. (If your shell is too smart to let the background process deal with itself, toss in a "disown %1" before exec-ing metis. Shells that do interactive-style process management when not interactive are broken, though.) - -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkyKVwwACgkQIn7hlCsL25ULkACfafrUFq15UNp8FnnfvtmtpP7E LfwAnA/8rX/k9E4nrqGB8cwB8kexId/5 =Hchn -----END PGP SIGNATURE-----

Hi Christian,
On Thu, Sep 9, 2010 at 4:35 AM, Christian Maeder
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.
Maybe you want to know that the latest version of Metis has a new --time-limit command line argument http://www.gilith.com/pipermail/metis-users/2010-September/000001.html Best regards, -- Andrés

Hi, thanks for pointing this out. Am 29.09.2010 06:47, schrieb Andrés Sicard-Ramírez:
Hi Christian,
On Thu, Sep 9, 2010 at 4:35 AM, Christian Maeder
wrote: 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.
Maybe you want to know that the latest version of Metis has a new --time-limit command line argument
http://www.gilith.com/pipermail/metis-users/2010-September/000001.html
This message also suggest "ulimit", though. We'll try it out the choices. Christian
Best regards,
participants (6)
-
Andrés Sicard-Ramírez
-
Brandon S Allbery KF8NH
-
Christian Maeder
-
David Peixotto
-
Edward Z. Yang
-
Simon Marlow