1
-- | This implements a watchdog process. It calls mueval with all the
2
-- user-specified arguments, sleeps, and then if mueval is still running
4
-- Even an out-of-control mueval will have trouble avoiding 'terminateProcess'.
5
-- Note that it's too difficult to parse the user arguments to get the timeout,
6
-- so we specify it as a constant which is a little more generous than the default.
9
import Control.Concurrent (forkIO, threadDelay)
10
import System.Environment (getArgs)
11
import System.Exit (exitWith, ExitCode(ExitFailure))
12
import System.Posix.Signals (signalProcess)
13
import System.Process (getProcessExitCode, runProcess, terminateProcess, waitForProcess)
14
import System.Process.Internals (withProcessHandle, ProcessHandle__(OpenHandle))
17
main = do args <- getArgs
18
hdl <- runProcess "mueval-core" args Nothing Nothing Nothing Nothing Nothing
20
threadDelay (7 * 700000)
21
status <- getProcessExitCode hdl
23
Nothing -> do terminateProcess hdl
24
_ <- withProcessHandle hdl (\x -> case x of
25
OpenHandle pid -> signalProcess 9 pid >> return (undefined, undefined)
26
_ -> return (undefined,undefined))
27
exitWith (ExitFailure 1)
29
stat <- waitForProcess hdl