uv.uv_signal_t
uv_signal_t - Signal handle
[uv_handle_t][] functions also apply.Signal handles implement Unix style signal handling on a per-event loop bases.
Windows Notes:
Reception of some signals is emulated on Windows:
- SIGINT is normally delivered when the user presses CTRL+C. However, like on
- SIGBREAK is delivered when the user pressed CTRL + BREAK.
- SIGHUP is generated when the user closes the console window. On SIGHUP the
- SIGWINCH is raised whenever libuv detects that the console has been resized.
- Watchers for other signals can be successfully created, but these signals
- Calls to raise() or abort() to programmatically raise a signal are not
Unix, it is not generated when terminal raw mode is enabled.
program is given approximately 10 seconds to perform cleanup. After that Windows will unconditionally terminate it.
SIGWINCH is emulated by libuv when the program uses a uvttyt handle to write to the console. SIGWINCH may not always be delivered in a timely manner; libuv will only detect size changes when the cursor is being moved. When a readable [uv_tty_t][] handle is used in raw mode, resizing the console buffer will also trigger a SIGWINCH signal.
are never received. These signals are: SIGILL, SIGABRT, SIGFPE, SIGSEGV, SIGTERM and SIGKILL.
detected by libuv; these will not trigger a signal watcher.
Unix Notes:
- SIGKILL and SIGSTOP are impossible to catch.
- Handling SIGBUS, SIGFPE, SIGILL or SIGSEGV via libuv results into undefined
- SIGABRT will not be caught by libuv if generated by abort(), e.g. through
- On Linux SIGRT0 and SIGRT1 (signals 32 and 33) are used by the NPTL pthreads
behavior.
assert().
library to manage threads. Installing watchers for those signals will lead to unpredictable behavior and is strongly discouraged. Future versions of libuv may simply reject them.
-- Create a new signal handler
local signal = uv.new_signal()
-- Define a handler function
uv.signal_start(signal, "sigint", function(signame)
print("got " .. signame .. ", shutting down")
os.exit(1)
end)
Methods3
function uv_signal_t.start(signame: string | integer, callback: fun(signame: string) -> nil) -> (success 0 | nil, err nil | string, err_name uv.error_name | nil)
Start the handle with the given callback, watching for the given signal.
See [Constants][] for supported signame input and output values.
function uv_signal_t.start_oneshot(signame: string | integer, callback: fun(signame: string) -> nil) -> (success 0 | nil, err nil | string, err_name uv.error_name | nil)
Same functionality as uv.signal_start() but the signal handler is reset the moment the signal is received.
See [Constants][] for supported signame input and output values.
function uv_signal_t.stop() -> (success 0 | nil, err nil | string, err_name uv.error_name | nil)
Stop the handle, the callback will no longer be called.