Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8860091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:12:03+00:00 2026-06-14T15:12:03+00:00

I tried the following approach: import System.Exit import System.Posix.Signals import Control.Concurrent (threadDelay) main ::

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:12:05+00:00Added an answer on June 14, 2026 at 3:12 pm

    From the docs of installHandler:

    a handler is installed which will invoke action in a new thread when (or shortly after) the signal is received.

    and exitWith:

    Note: in GHC, exitWith should be called from the main program thread in order to exit the process. When called from another thread, exitWith will throw an ExitException as normal, but the exception will not cause the process itself to exit.

    So an exitSuccess handler doesn’t end the process, and that’s expected (although unexpected 😉 behaviour.

    If you want immediate action,

    import System.Exit
    import System.Posix.Signals
    import Control.Concurrent
    
    main :: IO ()
    main = do
      tid <- myThreadId
      installHandler keyboardSignal (Catch (killThread tid)) Nothing
      threadDelay (1000000000)
    

    kills the thread immediately upon receiving the signal.

    Less drastic, if you want a successful exit, would be

    import System.Exit
    import System.Posix.Signals
    import Control.Concurrent
    import qualified Control.Exception as E
    
    main :: IO ()
    main = do
      tid <- myThreadId
      installHandler keyboardSignal (Catch (E.throwTo tid ExitSuccess)) Nothing
      threadDelay (10000000)
    

    I think it will also work reliably, but I’m not entirely sure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tried the following approach Make XAMPP/Apache serve file outside of htdocs but this
My goal I need to select the second option. I've tried following approach and
Tried following the instructions here: How to use Google app engine with my own
I tried following the instruction s but can't get the plugin to work, the
I tried following the gradle manual with their example like this but copyJars is
I tried following the answer here how to override a task making it depend
I tried following the following example to make an HTTP link in my TextView
I tried following the answer to this question , but could not get xsd.exe
I tried following the README file in Ruby 1.9.1 but I can't compile it
I tried following some of the code from here and here , but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.