1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 2 "http://www.w3.org/TR/REC-html40/loose.dtd"> 3<html> 4 5<head> 6<title>The Signal structure</title> 7<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 8<link href="docstyle.css" rel="stylesheet" type="text/css"> 9</head> 10 11<body bgcolor="#FFFFFF"> 12<ul class="nav"> 13 <li><a href="PolyMLStructure.html">Previous</a></li> 14 <li><a href="Basis.html">Up</a></li> 15 <li><a href="SingleAssignment.html">Next</a></li> 16</ul> 17 18<h2><font face="Arial"><strong>Signal structure</strong></font></h2> 19 20<p>Although the <tt>Posix</tt> structure in the Standard Basis Library provides functions 21which send signals to a process there is no standard method of handling signals. The 22<tt>Signal</tt> structure has been added to Poly/ML to allow signals to be blocked or 23handled.</p> 24 25<pre class="mainsig"> 26structure Signal: 27 sig 28 datatype sig_handle = SIG_DFL | SIG_IGN | SIG_HANDLE of int -> unit 29 val signal = fn : int * sig_handle -> sig_handle 30 end 31</pre> 32 33<p>The <tt>Signal.signal</tt> function takes as its arguments a signal number and an 34action and returns the previous action. The action may be <tt>SIG_DFL</tt>, 35indicating the default action, <tt>SIG_IGN</tt>, indicating that the signal should be 36ignored (blocked) or <tt>SIG_HANDLE</tt>, which allows a handler function to be installed. 37 </p> 38 39<p>Signals are represented as integers using the normal Unix signal numbering. In 40the Unix implementations of Poly/ML the type <tt>Posix.Signal.signal</tt> is the same as <tt>int</tt> 41so the constants from <tt>Posix.Signal</tt> can be used as arguments to <tt>Signal.signal</tt>. 42 </p> 43 44<p>The default action depends on the signal. For some signals it is to ignore the 45signal, for others the process is killed. See the signal man page in Unix for a list 46of the default actions. The only exception is the console interrupt signal, signal 47number 2. The default action here is to run the conventional Poly/ML console 48interrupt handler which prompts for various actions including getting a stack trace and 49raising an <tt>Interrupt</tt> exception.</p> 50 51<p>A handler function installed using <tt>SIG_HANDLE</tt> is run as a separate process 52(thread) some time after a signal arrives. </p> 53 54<p>Several signals, such as SIGSEGV, SIGFPE and SIGILL, are used internally by Poly/ML. 55 It is not possible to install a handler or block these signals. Although the 56SIGALRM (14) signal is used internally it is treated specially and a signal handler for 57SIGALRM may be installed. The handler will be run whenever the timer set up by <tt>Posix.Process.alarm</tt> 58expires as though the signal had been delivered. </p> 59 60<p>Signal actions installed using Signal.signal are persistent.</p> 61 62<p>The Signal structure is provided in the Windows implementation but only the 63 console interrupt signal (2) has effect.</p> 64<ul class="nav"> 65 <li><a href="PolyMLStructure.html">Previous</a></li> 66 <li><a href="Basis.html">Up</a></li> 67 <li><a href="SingleAssignment.html">Next</a></li> 68</ul> 69</body> 70</html> 71