<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html> <head> <title>The Signal structure</title> </head> <body bgcolor="#FFFFFF"> <h2><font face="Arial"><strong>Signal structure</strong></font></h2> <p>Although the <tt>Posix</tt> structure in the Standard Basis Library provides functions which send signals to a process there is no standard method of handling signals. The <tt>Signal</tt> structure has been added to Poly/ML to allow signals to be blocked or handled.</p> <p><tt>Signal:<br> sig<br> datatype sig_handle =<br> SIG_DFL | SIG_IGN | SIG_HANDLE of int -> unit<br> val signal = fn : int * sig_handle -> sig_handle<br> end</tt></p> <p>The <tt>Signal.signal</tt> function takes as its arguments a signal number and an action and returns the previous action. The action may be <tt>SIG_DFL</tt>, indicating the default action, <tt>SIG_IGN</tt>, indicating that the signal should be ignored (blocked) or <tt>SIG_HANDLE</tt>, which allows a handler function to be installed. </p> <p>Signals are represented as integers using the normal Unix signal numbering. In the Unix implementations of Poly/ML the type <tt>Posix.Signal.signal</tt> is the same as <tt>int</tt> so the constants from <tt>Posix.Signal</tt> can be used as arguments to <tt>Signal.signal</tt>. </p> <p>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 <tt>Interrupt</tt> exception.</p> <p>A handler function installed using <tt>SIG_HANDLE</tt> is run as a separate process (thread) some time after a signal arrives. </p> <p>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 <tt>Posix.Process.alarm</tt> expires as though the signal had been delivered. </p> <p>Signal actions installed using Signal.signal are persistent.</p> <p>The Signal structure is provided in the Windows implementation but only the console interrupt signal (2) has effect.</p> </body> </html>