[GHC] #10081: SIGTERM ignored when process has been detached from terminal

GHC ghc-devs at haskell.org
Sun Mar 8 18:56:31 UTC 2015


#10081: SIGTERM ignored when process has been detached from terminal
-------------------------------------+-------------------------------------
        Reporter:  nakal             |                   Owner:  ekmett
            Type:  bug               |                  Status:  new
        Priority:  normal            |               Milestone:
       Component:  Core Libraries    |                 Version:  7.8.3
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:  x86_64
 Type of failure:  Incorrect result  |  (amd64)
  at runtime                         |               Test Case:
      Blocked By:                    |                Blocking:
 Related Tickets:                    |  Differential Revisions:
-------------------------------------+-------------------------------------

Comment (by rwbarton):

 nakal: consider this program for instance

 {{{
 import Control.Concurrent
 import Control.Exception
 import Control.Monad
 import System.Exit
 import System.IO
 import System.Posix.Signals

 loop = forever $ threadDelay 1000000

 main = do
         ppid <- myThreadId
         mapM (\sig -> installHandler sig (Catch $ trap ppid) Nothing)
                 [ keyboardSignal ]
         loop

 trap tid = do
         hPutStrLn stderr "Signal received.\n"
         throwIO Overflow
         throwTo tid ExitSuccess
 }}}

 If you run it in a terminal and press ctrl-C, you will see
 {{{
 ^CSignal received.

 u: arithmetic overflow
 }}}
 and the program will keep running.

 ----

 To catch the exception from `hPutStrLn` you can simply do

 {{{
 import Control.Exception
 import Control.Concurrent
 import Control.Monad
 import System.Exit
 import System.IO
 import System.Posix.Signals

 loop = forever $ threadDelay 1000000

 main = do
         ppid <- myThreadId
         mapM (\sig -> installHandler sig (Catch $ trap ppid) Nothing)
                 [ lostConnection, keyboardSignal, softwareTermination,
 openEndedPipe ]
         loop

 trap tid = do
         let handler :: SomeException -> IO ()
             handler _ = return ()
         catch (hPutStrLn stderr "Signal received.\n") handler
         throwTo tid ExitSuccess
 }}}

 and now the program exits when run and killed as in your fourth test.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10081#comment:9>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list