with-signal-handler

$Revision: 5.0.2.2 $

Macro

Package: EXCL

Arguments: ((signo function) &rest body)

This macro installs a handler using function for signal number signo for the dynamic extent of the execution of body.

The handling of operating system dependent signals generated during program execution is not part of Common Lisp. A signal is a small integer. The list of valid signals is given in a system dependent file, usually on UNIX something like /usr/include/signals.h. Signals are either synchronous or asynchronous, but there is no distinction made in this interface--the handling of both types of signals is the same. A handler for a signal is a function of two arguments, signal number and t. If there is no handler for a particular signal, then some default action is invoked, which is usually to signal an error. Signals handlers should return a non-nil value if they handle the signal, so that other, nested handlers are are not invoked to handle the signal. A signal that is posted during a gc is processed immediately after the gc finishes.

;; This macro is defined in terms of the other signal handling
;; primitives, with some protection for multiprocessing as well:
(defmacro with-signal-handler ((signo function) &rest body)
  `(let ((func ,function))
    (without-interrupts (push (cons ,signo func) *signals*))
    (unwind-protect
        (progn ,@body)
      (without-interrupts
       (setq *signals*
         (delete ,signo *signals* :key #'car :count 1))))))

See also add-signal-handler (which has an example), set-signal-handler, *signals*, and remove-signal-handler.

The general documentation description is in introduction.htm. The index is in index.htm.

Copyright (C) 1998-1999, Franz Inc., Berkeley, CA. All Rights Reserved.