1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="docstyle.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF">
<ul class="nav">
<li><a href="PolyMLStructure.html">Previous</a></li>
<li><a href="Basis.html">Up</a></li>
<li><a href="SingleAssignment.html">Next</a></li>
</ul>
<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>
<pre class="mainsig">
structure Signal:
sig
datatype sig_handle = SIG_DFL | SIG_IGN | SIG_HANDLE of int -> unit
val signal = fn : int * sig_handle -> sig_handle
end
</pre>
<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>
<ul class="nav">
<li><a href="PolyMLStructure.html">Previous</a></li>
<li><a href="Basis.html">Up</a></li>
<li><a href="SingleAssignment.html">Next</a></li>
</ul>
</body>
</html>
|