File system categories
Platform
Signal Handling
Using XL Claire
Debugging

Signal Handling [XL]

Starting with XL CLAIRE we can install an Interrupt Service Routine written in CLAIRE for a particular signal. Signals, in XL CLAIRE, are not true asynchronous event since they are always caught by the Kernel as a first step and redistributed to the meta code from an appropriate execution point (necessary to preserve memory integrity) : the meta handling is always performed in the program execution flow (i.e. not in the stack of the signal handler) so that the code of the handler may be arbitrary complex.

The signal interface is very similar to C interface, we use signal(sig:signal_handler, p:property) to install a signal handler :
 user_interrupt() : void -> error("User interrupt")

 (signal(SIGUSR1user_interrupt))
 (raise(SIGUSR1)) // would throw the error above
Notice that in XL CLAIRE after the delivery of a signal the signal is always re-installed. To uninstall a handler one should use the special property SIG_DFL which correspond to a default handling :
 (signal(SIGUSR1SIG_DFL))
We could also ignore a signal using the special property SIG_IGN :
 (signal(SIGUSR1SIG_IGN))
Last, XL CLAIRE comes with another special property SIG_EXT that is set by default to a signal already installed at the time of CLAIRE initialization (as may be done by a library linked with CLAIRE).

However, SIGINT is handled in a particular way (SIGINT is on most UNIX raised with the keyboard when the user types ^C - Control + C). The SIGINT handler, when set to SIG_DFL (default), throws a user interrupt error such to abort the current computation and come back to the interpreter. If, additionally, the debugger is active, SIGINT would behave as a breakpoint.


categories Signal Handlingnormal dispatch [XL] Core method

getitimer(it:itimer) -> tuple(integer, integer)

getitimer returns the current values for timer it (i.e. the interval and the value).


categories Signal Handlingopen [XL] Core class

Core/itimer <: thing

Instances

ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF

UNIX timer interface can handle 3 kind of timers:


categories Signal Handlingnormal dispatch [XL] Kernel method

kill(p:integer, sig:signal_handler) -> void

send the signal sig to the process with pid p.


categories Signal Handlingnormal dispatch [XL] Core method

raise(sig:signal_handler) -> void

raise the given signal to the calling process


categories Signal Handlingnormal dispatch [XL] Core method

setitimer(it:itimer, interval:integer, value:integer) -> tuple(integer, integer)

setitimer sets a timer to the specified interval / value (in milliseconds). If value is non-zero, it indicates the time to the next timer expiration (at reload). If interval is non-zero, it specifies a value to be used in reloading value when the timer expires. Setting interval/value to 0/0 disables a timer. Setting interval to 0 causes a timer to be disabled after its next expiration (assuming value is non-zero). For instance we could implement a timeout as follow :
 timeout() : void -> error("Time out !")

 (signal(SIGALRMtimeout))

 (setitimer(ITIMER_REAL010000))
which would raise a time out exception after 10 seconds of (real time) processing.


categories Signal Handlingnormal dispatch [XL] Core method

sigblock(self:subtype[signal_handler]) -> set[signal_handler]

sigblock adds a set of signal to the process signal mask.


categories Signal Handlingnormal dispatch [XL] Core method

signal(sig:signal_handler, p:property) -> property

Install a signal handler for the given signal_handler. A restriction p should exists with the domain void. signal returns the old property associated with the signal handler. One may use special values for the handler p:

in a special way when assigned to SIG_DFL: the USER INTERRUPT. In CLAIRE signals are synchronously distributed to the meta code such to keep CLAIRE memory in a good shape. That is, there is a delay between the kernel routine that catches the signal and the execution of the meta handler.


categories Signal Handlingopen [XL] Core class

signal_handler <: thing

Instances

SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGEMT, SIGFPE, SIGKILL, SIGBUS, SIGSEGV, SIGSYS, SIGPIPE, SIGALRM, SIGTERM, SIGURG, SIGSTOP, SIGTSTP, SIGCONT, SIGCHLD, SIGTTIN, SIGTTOU, SIGIO, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF, SIGWINCH, SIGINFO, SIGUSR1, SIGUSR2

In claire signals are named objects. signal handling is system dependent and a signal_handler instance may not correspond to a supported signal in which case its value signo will be set to -1.


categories Signal Handlingnormal dispatch [XL] Core method

sigpending() -> set[signal_handler]

sigpending returns the set of signals that are currently blocked from delivery, i.e. the process has been signaled but the delivery is blocked until the signal is unblocked (sigunblock).


categories Signal Handlingnormal dispatch [XL] Core method

sigprocmask() -> set[signal_handler]

sigprocmask returns the set of signal that are part of the process signal mask, that is the set of signal that the subsystem blocks from delivery.


categories Signal Handlingnormal dispatch [XL] Core method

sigsetmask(self:subtype[signal_handler]) -> set[signal_handler]

sigsetmask sets the set of signal for the process signal mask, that is the set of signal that the subsystem blocks from delivery.


categories Signal Handlingnormal dispatch [XL] Core method

sigsuspend(self:subtype[signal_handler]) -> void

sigsuspend temporarily changes the process signal mask to the set sigs, and then wait for a signal to arrive; on return the previous set of masked signals is restored. The signal mask set is usually empty to indicate that all signals are to be unblocked for the duration of the call.


categories Signal Handlingnormal dispatch [XL] Core method

sigunblock(self:subtype[signal_handler]) -> set[signal_handler]

sigunblock removes a set of signal to the process signal mask.