Although the Posix structure in the Standard Basis Library provides functions which send signals to a process there is no standard method of handling signals. The Signal structure has been added to Poly/ML to allow signals to be blocked or handled.
structure Signal: sig datatype sig_handle = SIG_DFL | SIG_IGN | SIG_HANDLE of int -> unit val signal = fn : int * sig_handle -> sig_handle end
The Signal.signal function takes as its arguments a signal number and an action and returns the previous action. The action may be SIG_DFL, indicating the default action, SIG_IGN, indicating that the signal should be ignored (blocked) or SIG_HANDLE, which allows a handler function to be installed.
Signals are represented as integers using the normal Unix signal numbering. In the Unix implementations of Poly/ML the type Posix.Signal.signal is the same as int so the constants from Posix.Signal can be used as arguments to Signal.signal.
The default action depends on the signal. For some signals it is to ignore the signal, for others the process is killed. See the signal man page in Unix for a list of the default actions. The only exception is the console interrupt signal, signal number 2. The default action here is to run the conventional Poly/ML console interrupt handler which prompts for various actions including getting a stack trace and raising an Interrupt exception.
A handler function installed using SIG_HANDLE is run as a separate process (thread) some time after a signal arrives.
Several signals, such as SIGSEGV, SIGFPE and SIGILL, are used internally by Poly/ML. It is not possible to install a handler or block these signals. Although the SIGALRM (14) signal is used internally it is treated specially and a signal handler for SIGALRM may be installed. The handler will be run whenever the timer set up by Posix.Process.alarm expires as though the signal had been delivered.
Signal actions installed using Signal.signal are persistent.
The Signal structure is provided in the Windows implementation but only the console interrupt signal (2) has effect.