Guaranteed termination of external process in Haskell -


i have launched ghci external process this

(just hin, hout, _, pid) <- createprocess (proc "ghci" ["-fdefer-type-errors"])     { std_in = createpipe, std_out = createpipe, std_err = usehandle stdout }  

which control writing hin , reading hout. used load haskell file external ghci process, call 1 of functions, , read results, problematic.

my problem there function runs indefinetely when called, f n = sum [n..], , when happens want terminate external ghci process.

to so, have tried calling function terminateprocess pid not kill process reliably; in general, external process stops working, yet still appears when type $ ps @ console. example, example of top's output when ghc external process eating processor:

pid    command      %cpu  time      ... 38312  top          3.3   00:00.89  38309  ghc          99.9  00:21.46  38306  ghc          0.0   00:00.82  

and when try end using terminateprocess pid brings down process 0% cpu, still there:

pid    command      %cpu     time      ... 38312  top          3.3   00:00.89 38309  ghc          0.0   00:21.46  38306  ghc          0.0   00:00.82  

sometimes, need call terminateprocess pid several times make external ghc stop, yet sill there. then, after stopped, when try waitforprocess pid 1 blocks.

is there reliable way in haskell terminate external process sure? unix kill -9 38309 does?

thanks

on posix systems terminateprocess sends sigterm signal.

here code demonstrates how send sigkill signal posix process created using system.process:

import system.process import system.process.internals import system.posix.signals  main =   (_, _, _, ph) <- createprocess (shell "asd")   -- ...   withprocesshandle ph $ \ph_ ->     case ph_ of       openhandle pid -> signalprocess sigkill pid       closedhandle _ -> return ()                   -- shouldn't happen 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -