I tried the following approach:
import System.Exit
import System.Posix.Signals
import Control.Concurrent (threadDelay)
main :: IO ()
main = do
installHandler keyboardSignal (Catch (do exitSuccess)) Nothing
threadDelay (1000000000)
But it only outputs:
^CTest.hs: ExitSuccess
on Ctrl-C, instead of exiting. How should I do it properly?
From the docs of
installHandler:and
exitWith:So an
exitSuccesshandler doesn’t end the process, and that’s expected (although unexpected 😉 behaviour.If you want immediate action,
kills the thread immediately upon receiving the signal.
Less drastic, if you want a successful exit, would be
I think it will also work reliably, but I’m not entirely sure.