annotate docs/ccguide/signal.refentry @ 3295:6b7a7b233925 default tip

makefile: Allow PORTS with level1/2 mix https://sourceforge.net/p/nitros9/feature-requests/10/
author Tormod Volden <debian.tormod@gmail.com>
date Tue, 19 Apr 2022 18:12:17 +0200
parents 8a16d38f3d94
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
1 <refentry id="signal">
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
2 <refnamediv>
468
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
3 <refname>Signal</refname>
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
4 <refpurpose>catch or ignore interrupts</refpurpose>
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
5 </refnamediv>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
6
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
7 <refsynopsisdiv>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
8 <funcsynopsis>
468
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
9 <funcsynopsisinfo>
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
10 #include &lt;signal.h&gt;
578
ed2a3bb12458 All function prototypes are added.
roug
parents: 557
diff changeset
11
ed2a3bb12458 All function prototypes are added.
roug
parents: 557
diff changeset
12 typedef int (*sighandler_t)(int);
468
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
13 </funcsynopsisinfo>
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
14 <funcprototype>
578
ed2a3bb12458 All function prototypes are added.
roug
parents: 557
diff changeset
15 <funcdef>sighandler_t <function>signal</function></funcdef>
ed2a3bb12458 All function prototypes are added.
roug
parents: 557
diff changeset
16 <paramdef>int <parameter>interrupt</parameter></paramdef>
ed2a3bb12458 All function prototypes are added.
roug
parents: 557
diff changeset
17 <paramdef>sighandler_t <parameter>address</parameter></paramdef>
ed2a3bb12458 All function prototypes are added.
roug
parents: 557
diff changeset
18
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
19 </funcprototype>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
20 </funcsynopsis>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
21
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
22 </refsynopsisdiv>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
23
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
24 <refsect1><title>Description</title>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
25 <para>
557
7d803625ead8 Signal is not finished at all.
roug
parents: 556
diff changeset
26 This call is a comprehensive method of catching or ignoring
7d803625ead8 Signal is not finished at all.
roug
parents: 556
diff changeset
27 signals sent to the current process. Notice that "kill()" does
7d803625ead8 Signal is not finished at all.
roug
parents: 556
diff changeset
28 the sending of signals, and "signal()" does the catching.
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
29 </para>
556
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
30 <para>
607
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
31 Normally, a signal sent to a process causes it to terminate
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
32 with the status of the signal. If, in advance of the
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
33 anticipated signal, this system call is used, the program has
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
34 the choice of ignoring the signal or designating a function to
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
35 be executed when it is received. Different functions may be
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
36 designated for different signals.
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
37 </para>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
38 <para>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
39 The values for "address" have the following meanings:
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
40 <informaltable frame="none">
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
41 <tgroup cols="2">
640
8a16d38f3d94 Convert to Docbook XML format
roug
parents: 611
diff changeset
42 <colspec colwidth="0.7in"/>
8a16d38f3d94 Convert to Docbook XML format
roug
parents: 611
diff changeset
43 <colspec colwidth="3in"/>
607
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
44 <tbody>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
45 <row>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
46 <entry>0</entry>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
47 <entry>reset to the default i.e. abort when received.</entry>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
48 </row>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
49 <row>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
50 <entry>1</entry>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
51 <entry>ignore; this will apply until reset to another value.</entry>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
52 </row>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
53 <row>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
54 <entry>Otherwise</entry>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
55 <entry>taken to be the address of a C function which
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
56 is to be executed on receipt of the signal.</entry>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
57 </row>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
58 </tbody>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
59 </tgroup>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
60 </informaltable>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
61 </para>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
62 <para>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
63 If the latter case is chosen, when the signal is received by
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
64 the process the "address" is reset to 0, the default, before
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
65 the function is executed. This means that if the next signal
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
66 received should be caught then another call to "signal()"
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
67 should be made immediately. This is normally the first action
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
68 taken by the "interrupt" function. The function may access the
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
69 signal number which caused its execution by looking at its
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
70 argument. On completion of this function the program resumes
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
71 at the point at which is was "interrupted" by the signal.
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
72 </para>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
73 <para>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
74 An example should help to clarify all this. Suppose a program
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
75 needs to create a temporary file which should be deleted before
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
76 exiting. The body of the program might contain fragments like
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
77 this:
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
78 <programlisting>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
79 pn = creat("temp",3); /* create a temporary file */
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
80 signal(2,intrupt); /* ensure tidying up */
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
81 signal(3,intrupt);
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
82 write(pn,string,count);
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
83 close(pn); /* finished writing */
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
84 unlink("temp"); /* delete it */
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
85 exit(0); /* normal exit */
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
86 </programlisting>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
87 The call to "signal()" will ensure that if a keyboard or quit
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
88 signal is received then the function "intrupt()" will be
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
89 executed and this might be written:
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
90 <programlisting>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
91 intrupt(sig)
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
92 {
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
93 close(pn); /* close it if open */
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
94 unlink("temp"); /* delete it */
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
95 exit(sig); /* received signal er exit status */
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
96 }
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
97 </programlisting>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
98 </para>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
99 <para>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
100 In this case, as the function will be exiting before another
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
101 signal is received, it is unnecessary to call "signal()" again
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
102 to reset its pointer. Note that either the function
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
103 "intrupt()" should appear in the source code before the call to
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
104 "signal()", or it should be pre-declared.
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
105 </para>
183184bacb3d All refentries finished.
roug
parents: 578
diff changeset
106 <para>
556
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
107 The signals used by OS-9 are defined in the header file as
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
108 follows:
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
109 </para>
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
110 <programlisting>
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
111 /* OS-9 signals */
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
112 #define SIGKILL 0 /* system abort (cannot be caught or ignored)*/
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
113 #define SIGWAKE 1 /* wake up */
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
114 #define SIGQUIT 2 /* keyboard abort */
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
115 #define SIGINT 3 /* keyboard interrupt */
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
116
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
117 /* special addresses */
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
118 #define SIG_DFL 0 /* reset to default */
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
119 #define SIG_IGN 1 /* ignore */
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
120 </programlisting>
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
121 <para>
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
122 Please note that there is another method of trapping signals,
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
123 namely "intercept()" (q.v.). However, since "signal()" and
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
124 "intercept()" are mutually incompatible, calls to both of them
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
125 must not appear in the same program. The link-loader will
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
126 preven the creation of an executable program in which both are
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
127 called by aborting with an "entry name clash" error for
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
128 "_sigint".
28a203bbd2cc findstr and signal finished.
roug
parents: 544
diff changeset
129 </para>
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
130 </refsect1>
544
ba824286a6a0 All "See Also" implemented
roug
parents: 468
diff changeset
131
ba824286a6a0 All "See Also" implemented
roug
parents: 468
diff changeset
132 <refsect1><title>See Also</title>
ba824286a6a0 All "See Also" implemented
roug
parents: 468
diff changeset
133 <para>
ba824286a6a0 All "See Also" implemented
roug
parents: 468
diff changeset
134 <link linkend="intercept">intercept()</link>,
ba824286a6a0 All "See Also" implemented
roug
parents: 468
diff changeset
135 OS-9 shell command "kill",
ba824286a6a0 All "See Also" implemented
roug
parents: 468
diff changeset
136 <link linkend="kill">kill()</link>
ba824286a6a0 All "See Also" implemented
roug
parents: 468
diff changeset
137 </para>
ba824286a6a0 All "See Also" implemented
roug
parents: 468
diff changeset
138 </refsect1>
ba824286a6a0 All "See Also" implemented
roug
parents: 468
diff changeset
139
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
140 </refentry>