문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top