how to terminate an external program after timeout?

Brandon S Allbery KF8NH allbery at
Fri Sep 10 12:04:28 EDT 2010

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 at
system administrator  [openafs,heimdal,too many hats]  allbery at
electrical and computer engineering, carnegie mellon university      KF8NH
Version: GnuPG v2.0.10 (Darwin)
Comment: Using GnuPG with Mozilla -


More information about the Glasgow-haskell-users mailing list