3 notify, noted, atnotify, noteenable, notedisable, notifyon, notifyoff \- handle asynchronous process notification
10 int notify(void (*f)(void*, char*))
16 int atnotify(int (*f)(void*, char*), int in)
19 int noteenable(char *msg)
22 int notedisable(char *msg)
25 int notifyon(char *msg)
28 int notifyoff(char *msg)
30 When a process raises an exceptional condition such as dividing by zero
31 or writing on a closed pipe, a
33 is posted to communicate the exception.
34 A note may also be posted by another process
37 On Unix, notes are implemented as signals.
39 When a note is received, the action taken depends on the note.
42 for the full description of the defaults.
44 The default actions may be overridden.
48 .I "notification handler
49 to be called within the process when a note is received.
52 replaces the previous handler, if any.
53 An argument of zero cancels a previous handler,
54 restoring the default action.
57 system call leaves the handler registered in
58 both the parent and the child;
60 restores the default behavior.
61 Handlers may not perform floating point operations.
63 After a note is posted,
64 the handler is called with two arguments:
65 the first is unimplemented and should not be used
70 giving the current values of registers);
71 the second is a pointer to the note itself,
72 a null-terminated string.
75 .\" argument is usually not needed; it is provided to help recover from traps such
76 .\" as floating point exceptions.
77 .\" Its use and layout are machine- and system-specific.
79 A notification handler must finish either by exiting the program or by calling
81 if the handler returns the behavior
82 is undefined and probably erroneous.
83 Until the program calls
85 any further externally-generated notes
90 will be held off, and any further notes generated by
91 erroneous behavior by the program
92 (such as divide by zero) will kill the program.
95 defines the action to take:
97 instructs the system to perform the default action
98 as if the handler had never been registered;
100 instructs the system to resume the process
101 at the point it was notified.
104 return to the handler.
105 If the note interrupted an incomplete system call,
106 that call returns an error (with error string
108 after the process resumes.
109 A notification handler can also jump out to an environment
117 Unix provides a fixed set of notes (typically there are 32) called
119 It also allows a process to block certain notes from being delivered
122 and to ignore certain notes by setting the signal hander to the special value
129 enable or disable receipt of a particular note by changing the current process's blocked signal mask.
130 Receipt of a disabled note will be postponed until it is reenabled.
134 enable or disable whether the notification handler
135 is called upon receipt of the note; if the handler is not called, the note is discarded.
137 Regardless of the origin of the note or the presence of a handler,
138 if the process is being debugged
141 the arrival of a note puts the process in the
143 state and awakens the debugger.
145 Rather than using the system calls
149 most programs should use
151 to register notification handlers.
154 is non-zero to register the function
156 and zero to cancel registration.
157 A handler must return a non-zero number
158 if the note was recognized (and resolved);
159 otherwise it must return zero.
160 When the system posts a note to the process,
161 each handler registered with
163 is called with arguments as
165 until one of the handlers returns non-zero.
168 is called with argument
170 If no registered function returns non-zero,
178 .\" has two other possible values for its argument.
180 .\" returns from the handler and clears the note, enabling the receipt of another,
181 .\" but does not return to the program.
182 .\" Instead it starts a new handler with the same stack, stack pointer,
183 .\" and arguments as the
184 .\" original, at the address recorded in the program counter of the
186 .\" structure. Typically, the program counter will be overridden by the
187 .\" first note handler to be the address of a separate function;
189 .\" is then a `trampoline' to that handler.
190 .\" That handler may executed
192 .\" to return to the original program, usually after restoring the original program
197 .\" except that it can only be executed after an
202 .\" are designed to improve the emulation of signals by the ANSI C/POSIX
203 .\" environment; their use elsewhere is discouraged.
208 return \-1 on error and 0 on success.
210 returns \-1 on error; successful calls to
219 return \-1 on error, 0 if the note was previously disabled (not notified),
220 and 1 if the note was previously enabled (notified).
222 The set of notes a process may receive is system-dependent, but there
223 is a common set that includes:
227 .ta \w'\fLsys: segmentation violation \fP'u +\w'process requested to exit 'u
228 \fINote\fP \fIMeaning\fP \fIUnix signal\fP
229 \fLinterrupt\fP user interrupt (DEL key) SIGINTR
230 \fLhangup\fP I/O connection closed SIGHUP
231 \fLalarm\fP alarm expired SIGLARM
232 \fLquit\fP quit from keyboard SIGQUIT
233 \fLkill\fP process requested to exit SIGTERM
234 \fLsys: kill\fP process forced to exit SIGKILL
235 \fLsys: bus error\fP bus error SIGBUS
236 \fLsys: segmentation violation\fP segmentation violation SIGSEGV
237 \fLsys: write on closed pipe\fP write on closed pipe SIGPIPE
238 \fLsys: child\fP child wait status change SIGCHLD
243 .B \*9/src/lib9/await.c
249 are usually generated by the operating system.
251 .B \*9/src/lib9/notify.c
253 .B \*9/src/lib9/atnotify.c