Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correctly terminate spawned runghc process

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

like image 495
amindfv Avatar asked May 14 '14 15:05

amindfv


1 Answers

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.

like image 123
Daniel Wagner Avatar answered Nov 01 '22 03:11

Daniel Wagner