Question

With a script like

-- foo.hs
import System.Process
import Control.Concurrent

main = do
   a <- runCommand "yes"
   threadDelay 1000000
   terminateProcess a

I get expected behavior -- yes runs until the threadDelay is up. But if I replace "yes" with "runghc bar.hs", where bar.hs is

import Control.Monad
import Control.Concurrent

main = forever (print 5 >> threadDelay 100000)

...then bar.hs runs forever. Is there a better way to get runghc to terminate?

Edit: This behavior is on linux

Was it helpful?

Solution

That's pretty funny behavior. What's going on is that runghc spawns its own child process, and you kill the runghc process but not the child. Using interruptProcessGroupOf in place of terminateProcess seems to do the trick here, though I don't really know enough to say whether that's a reliable/correct solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top