Qore Programming Language Reference Manual 2.0.0
|
Qore implements safe signal handling on UNIX platforms (not available on native Microsoft Windows ports). Signals do not interrupt Qore threads, rather Qore uses a special signal handling thread with TID 0, dedicated to handling signals. The signal handling thread uses very few resources; it stays blocked (using no processor time and very little memory) until a signal with a Qore signal handler is raised; it then executes the handler and resumes waiting for signals.
Because Qore's signal handling thread is not a normal thread, it does not affect num_threads() and does not appear in the list returned by thread_list().
Internally, Qore masks (blocks) all signals in every thread except the signal handling thread. In the signal handling thread, all signals are unmasked, except those with Qore-language handlers, then an internal call to sigwait() (3)
is made to receive and process signals raised one at a time.
Qore-language signal handlers are installed by passing a signal constant and a closure or call reference to the code to execute when the signal is raised to the set_signal_handler() function. Signal handlers are removed by passing a signal constant to the remove_signal_handler() function.
When a signal has been raised and the signal handler is called, the signal number is passed as the sole argument to the signal handler code.
Signal Handling Functions
Function Name | Description |
set_signal_handler() | Sets up a Qore signal handler using a signal number and a call reference. |
remove_signal_handler() | Removes a Qore signal handler using a signal number. |
See Signal Constants for a list of signal constants and Qore::NameToSignal and Qore::SignalToName for two hash constants that can be used to map signal names to numbers and vice-versa. Note that signal constants are system-dependent; not all signals will be available in all systems; in case of doubt, see your system documentation for information on which signals are available.
The above functions are atomic, meaning that when they return to the caller, the signal handling thread has already acknowledged the changes.
It is not possible to set signal masks per thread; all signals are delivered to the signal handling thread. Signals not handled with a Qore signal handler are handled with their default action. It is not possible to catch SIGPIPE
. SIGPIPE
is always ignored in Qore.
Some issues to be aware of in signal handlers:
If a signal handler executes the thread_exit statement, execution of the signal handler will terminate immediately, but the signal handling thread will not be stopped. Execution of further signal handlers (including that for the same signal being handled when thread_exit is executed) will not be affected.