Re: signal handling weirdness

2005-04-17 Thread Lemmih
On 4/17/05, Volker Wysk <[EMAIL PROTECTED]> wrote:
> Hello.
> 
> I'm trying to install a handler for the TERM signal:
> 
> import System.Posix.Signals
> import System.Posix.Unistd
> import Monad
> 
> main =
>do installHandler sigTERM handler Nothing
>   sequence (repeat (putStrLn "bla" >> sleep 5))
>   return ()
> 
> handler = Catch (putStrLn "caught SIGTERM")
> -- handler = Ignore
> 
> When you type ^C, the current pause gets cut short, but the program continues
> to output "bla". It then terminates after another three to five "bla"'s.
> Installing a signal handler has no effect at all, regardless of whether it's
> Ignore or Catch (...).
> 
> /tmp $ ghc -o sig sig.hs  -package posix
> /tmp $ ./sig
> bla
> bla
> bla
> bla
> bla
> sig: interrupted
> 
> I'm using GHC 6.4 on Debian Linux.

>From sleep(3): "sleep()  makes  the  current  process  sleep  until 
'seconds' seconds have elapsed or a signal arrives which is not
ignored."
So 'sleep' returns when a signal arrives and C-c emits an interrupt
signal (sigINT) and not a termination signal (sigTERM), which is why
the pause gets cut short.
You may wanna use Control.Concurrent.threadDelay instead of sleep.

-- 
Friendly,
  Lemmih
___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


signal handling weirdness

2005-04-17 Thread Volker Wysk
Hello.

I'm trying to install a handler for the TERM signal:


import System.Posix.Signals
import System.Posix.Unistd
import Monad

main =
   do installHandler sigTERM handler Nothing
  sequence (repeat (putStrLn "bla" >> sleep 5))
  return ()

handler = Catch (putStrLn "caught SIGTERM")
-- handler = Ignore


When you type ^C, the current pause gets cut short, but the program continues 
to output "bla". It then terminates after another three to five "bla"'s. 
Installing a signal handler has no effect at all, regardless of whether it's 
Ignore or Catch (...).


/tmp $ ghc -o sig sig.hs  -package posix
/tmp $ ./sig
bla
bla
bla
bla
bla
sig: interrupted


I'm using GHC 6.4 on Debian Linux.


Bye,
V.W.
___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs