changeset 607:183184bacb3d

All refentries finished.
author roug
date Fri, 15 Nov 2002 21:49:51 +0000
parents dc24f1974396
children 5894df624e1a
files docs/ccguide/signal.refentry
diffstat 1 files changed, 76 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/docs/ccguide/signal.refentry	Fri Nov 15 21:49:51 2002 +0000
+++ b/docs/ccguide/signal.refentry	Fri Nov 15 21:49:51 2002 +0000
@@ -28,6 +28,82 @@
 the sending of signals, and "signal()" does the catching.
 </para>
 <para>
+Normally, a signal sent to a process causes it to terminate
+with the status of the signal. If, in advance of the
+anticipated signal, this system call is used, the program has
+the choice of ignoring the signal or designating a function to
+be executed when it is received. Different functions may be
+designated for different signals.
+</para>
+<para>
+The values for "address" have the following meanings:
+<informaltable frame="none">
+<tgroup cols="2">
+<colspec colwidth="0.5in">
+<colspec colwidth="3in">
+<tbody>
+<row>
+<entry>0</entry>
+<entry>reset to the default i.e. abort when received.</entry>
+</row>
+<row>
+<entry>1</entry>
+<entry>ignore; this will apply until reset to another value.</entry>
+</row>
+<row>
+<entry>Otherwise</entry>
+<entry>taken to be the address of a C function which
+is to be executed on receipt of the signal.</entry>
+</row>
+</tbody>
+</tgroup>
+</informaltable>
+</para>
+<para>
+If the latter case is chosen, when the signal is received by
+the process the "address" is reset to 0, the default, before
+the function is executed. This means that if the next signal
+received should be caught then another call to "signal()"
+should be made immediately. This is normally the first action
+taken by the "interrupt" function. The function may access the
+signal number which caused its execution by looking at its
+argument. On completion of this function the program resumes
+at the point at which is was "interrupted" by the signal.
+</para>
+<para>
+An example should help to clarify all this. Suppose a program
+needs to create a temporary file which should be deleted before
+exiting. The body of the program might contain fragments like
+this:
+<programlisting>
+pn  =  creat("temp",3);          /*  create  a temporary file */
+signal(2,intrupt);               /*   ensure   tidying   up   */
+signal(3,intrupt);
+write(pn,string,count);
+close(pn);                       /* finished writing */
+unlink("temp");                  /* delete it */
+exit(0);                         /* normal exit */
+</programlisting>
+The call to "signal()" will ensure that if a keyboard or quit
+signal is received then the function "intrupt()" will be
+executed and this might be written:
+<programlisting>
+intrupt(sig)
+{
+close(pn);                 /* close it if open */
+unlink("temp");            /* delete it */
+exit(sig);                 /* received signal er exit status */
+}
+</programlisting>
+</para>
+<para>
+In this case, as the function will be exiting before another
+signal is received, it is unnecessary to call "signal()" again
+to reset its pointer. Note that either the function
+"intrupt()" should appear in the source code before the call to
+"signal()", or it should be pre-declared.
+</para>
+<para>
 The signals used by OS-9 are defined in the header file as
 follows:
 </para>