Signals

STK allows the use to associate handlers to signals. Signal handlers for a given signal can even be chained in a list. When a signal occurs, the first signal of the list is executed. Unless this signal yields the symbol ndexfile(index-entry "break" "tt" aux )break the next signal of the list is evaluated. When a signal handler is called, the integer value of this signal is passed to it as (the only) parameter.

The following POXIX.1ndexfile(index-entry "POSIX.1" "rm" main ) constants for signal numbers are defined: ndexfile(index-entry "SIGABRT" "tt" aux )SIGABRT, ndexfile(index-entry "SIGALRM" "tt" aux )SIGALRM, ndexfile(index-entry "SIGFPE" "tt" aux )SIGFPE, ndexfile(index-entry "SIGHUP" "tt" aux )SIGHUP, ndexfile(index-entry "SIGILL" "tt" aux )SIGILL, ndexfile(index-entry "SIGINT" "tt" aux )SIGINT, ndexfile(index-entry "SIGKILL" "tt" aux )SIGKILL, ndexfile(index-entry "SIGPIPE" "tt" aux )SIGPIPE, SIGQUIT, ndexfile(index-entry "SIGSEGV" "tt" aux )SIGSEGV, ndexfile(index-entry "SIGTERM" "tt" aux )SIGTERM, ndexfile(index-entry "SIGUSR1" "tt" aux )SIGUSR1, SIGUSR2, ndexfile(index-entry "SIGCHLD" "tt" aux )SIGCHLD, ndexfile(index-entry "SIGCONT" "tt" aux )SIGCONT, ndexfile(index-entry "SIGSTOP" "tt" aux )SIGSTOP, SIGTSTP, ndexfile(index-entry "SIGTTIN" "tt" aux )SIGTTIN, ndexfile(index-entry "SIGTTOU" "tt" aux )SIGTTOU. Moreover, the following constants, which are often available on most systems are also defined3: ndexfile(index-entry "SIGTRAP" "tt" aux )SIGTRAP, ndexfile(index-entry "SIGIOT" "tt" aux )SIGIOT, SIGEMT, ndexfile(index-entry "SIGBUS" "tt" aux )SIGBUS, ndexfile(index-entry "SIGSYS" "tt" aux )SIGSYS, ndexfile(index-entry "SIGURG" "tt" aux )SIGURG, ndexfile(index-entry "SIGCLD" "tt" aux )SIGCLD, ndexfile(index-entry "SIGIO" "tt" aux )SIGIO, ndexfile(index-entry "SIGPOLL" "tt" aux )SIGPOLL, ndexfile(index-entry "SIGXCPU" "tt" aux )SIGXCPU, ndexfile(index-entry "SIGXFSZ" "tt" aux )SIGXFSZ, SIGVTALRM, ndexfile(index-entry "SIGPROF" "tt" aux )SIGPROF, ndexfile(index-entry "SIGWINCH" "tt" aux )SIGWINCH, ndexfile(index-entry "SIGLOST" "tt" aux )SIGLOST.

See your Unix documentation for the exact meaning of each constant or [#!Posix.1-90!#]. Use symbolic constants rather than their numeric value if you plan to port your program on another system.

A special signal, managed by the interpreter, is also defined: SIGHADGC. This signal is raised when the garbage collector phase terminates.

When the interpreter starts running, all signals are sets to their default value, excepted ndexfile(index-entry "SIGINT" "tt" aux )SIGINT (generally bound to ndexfile(index-entry "C" "tt" aux )Control-C) which is handled specially.





`=̀13`(ndexfile(index-entry "set-signal-handler!" "tt" main )set-signal-handler!sig handler)
procedure
Replace the handler for signal sig with handler. Handler can be
- #t to reset the signal handler for sig to the default system handler.
- #f to completly ignore sig (Note that Posix.1 states that ndexfile(index-entry "SIGKILL" "tt" aux )SIGKILL and ndexfile(index-entry "SIGSTOP" "tt" aux )SIGSTOP cannot be caught or ignored).
- a one parameter procedure.
This procedure returns the new handler, or (length 1) handler list, associated to sig.

$\Longrightarrow$
$\Longrightarrow$ unspecified error makeotherˆ`=̀13`


          gobblecr(let* ((x       #f)       (handler (lambda (i) (set! x #t))))  (set-signal-handler! |SIGHADGC| handler)  (gc)  x)  #t





`=̀13`(ndexfile(index-entry "add-signal-handler!" "tt" main )add-signal-handler!sig handler)
procedure
Adds handler to the list of handlers for signal sig. If the old signal handler is a boolean, this procedure is equivalent to ndexfile(index-entry "set-signal-handler!" "tt" aux )set-signal-handler!. Otherwise, the new handler is added in front of the previous list of handler. This procedure returns the new handler, or handler list, associated to sig.

$\Longrightarrow$
$\Longrightarrow$ unspecified error makeotherˆ`=̀13`


          gobblecr(let* ((x        '())       (handler1 (lambda (i) (set! x (cons 1 x))))       (handler2 (lambda (i) (set! x (cons 2 x)))))  (add-signal-handler! |SIGHADGC| handler1)  (add-signal-handler! |SIGHADGC| handler2)  (gc)  x)  (1 2)
$\Longrightarrow$
$\Longrightarrow$ unspecified error makeotherˆ`=̀13`

          gobblecr(let* ((x        '())       (handler1 (lambda (i) (set! x (cons 1 x))))       (handler2 (lambda (i) (set! x (cons 2 x)) 'break)))  (add-signal-handler! |SIGHADGC| handler1)  (add-signal-handler! |SIGHADGC| handler2)  (gc)  x)  (2)





`=̀13`(ndexfile(index-entry "get-signal-handlers" "tt" main )get-signal-handlers)
procedure
`=̀13`(ndexfile(index-entry "get-signal-handlers" "tt" main )get-signal-handlerssig)
procedure
Returns the handlers, or the list of handlers, associated to the signal sig. If sig is omitted, ndexfile(index-entry "get-signal-handlers" "tt" aux )get-signal-handlers returns a vector of all the signal handlers currently in effect.