[Haskell-cafe] control-c only caught once -- bug?

Donn Cave donn at avvanta.com
Sun Oct 30 18:33:00 CET 2011

Quoth Brian Johnson <brianjohnsonhaskellcafe at gmail.com>,
> On further thought, there is something sensible here: the RTS might crash
> while trying to exit.  I propose, for POSIX environments, the following
> change to SIGINT handling:
> * SIGINT is transformed into UserInterrupt during normal program execution
> * Once the RTS is committed to exiting, it resets the signal handler for
> SIGINT so that any additional control-c causes an immediate exit

The picture I get from the commentary (below) is that we're talking
about shutting down, one way or another - either "gracefully", or
if that isn't making satisfactory progress, abruptly on the second ^C.
Because the user entered a keyboard interrupt, and the program hasn't
installed a signal handler for it.  If you have your own shutdown
procedure that you want to have happen at that time, then it would
make sense to me to catch this exception for that purpose.

If you want to handle keyboard interrupts, throughout the lifetime
of the program process, then you should handle the signals.

If the SIGINT handler described below is too confusing, then I would
solve that problem by simply removing it.  Programs written in other
languages simply abort on unhandled signals, and I'm a little skeptical
that there's any reliable way to improve on that.  We're just teaching
people to press <ctrl>C twice if it's a Haskell program.


> From http://hackage.haskell.org/trac/ghc/wiki/Commentary/Rts/Signals:
>> "When the interrupt signal is received, the default behaviour of the
>> runtime is to attempt to shut down the Haskell program gracefully. It does
>> this by calling interruptStgRts() in rts/Schedule.c<http://hackage.haskell.org/trac/ghc/browser/rts/Schedule.c>
>>  (see Commentary/Rts/Scheduler#ShuttingDown<http://hackage.haskell.org/trac/ghc/wiki/Commentary/Rts/Scheduler#ShuttingDown>).
>> If a second interrupt signal is received, then we terminate the process
>> immediately; this is just in case the normal shutdown procedure failed or
>> hung for some reason, the user is always able to stop the process with two
>> control-C keystrokes"

More information about the Haskell-Cafe mailing list