1*fbb2e0a3Schristos 2*fbb2e0a3Schristos.. _signal: 3*fbb2e0a3Schristos 4*fbb2e0a3Schristos:c:type:`uv_signal_t` --- Signal handle 5*fbb2e0a3Schristos======================================= 6*fbb2e0a3Schristos 7*fbb2e0a3SchristosSignal handles implement Unix style signal handling on a per-event loop bases. 8*fbb2e0a3Schristos 9*fbb2e0a3SchristosWindows notes 10*fbb2e0a3Schristos------------- 11*fbb2e0a3Schristos 12*fbb2e0a3SchristosReception of some signals is emulated: 13*fbb2e0a3Schristos 14*fbb2e0a3Schristos* SIGINT is normally delivered when the user presses CTRL+C. However, like 15*fbb2e0a3Schristos on Unix, it is not generated when terminal raw mode is enabled. 16*fbb2e0a3Schristos 17*fbb2e0a3Schristos* SIGBREAK is delivered when the user pressed CTRL + BREAK. 18*fbb2e0a3Schristos 19*fbb2e0a3Schristos* SIGHUP is generated when the user closes the console window. On SIGHUP the 20*fbb2e0a3Schristos program is given approximately 10 seconds to perform cleanup. After that 21*fbb2e0a3Schristos Windows will unconditionally terminate it. 22*fbb2e0a3Schristos 23*fbb2e0a3Schristos* SIGWINCH is raised whenever libuv detects that the console has been 24*fbb2e0a3Schristos resized. When a libuv app is running under a console emulator, or when a 25*fbb2e0a3Schristos 32-bit libuv app is running on 64-bit system, SIGWINCH will be emulated. In 26*fbb2e0a3Schristos such cases SIGWINCH signals may not always be delivered in a timely manner. 27*fbb2e0a3Schristos For a writable :c:type:`uv_tty_t` handle libuv will only detect size changes 28*fbb2e0a3Schristos when the cursor is moved. When a readable :c:type:`uv_tty_t` handle is used, 29*fbb2e0a3Schristos resizing of the console buffer will be detected only if the handle is in raw 30*fbb2e0a3Schristos mode and is being read. 31*fbb2e0a3Schristos 32*fbb2e0a3Schristos* Watchers for other signals can be successfully created, but these signals 33*fbb2e0a3Schristos are never received. These signals are: `SIGILL`, `SIGABRT`, `SIGFPE`, `SIGSEGV`, 34*fbb2e0a3Schristos `SIGTERM` and `SIGKILL.` 35*fbb2e0a3Schristos 36*fbb2e0a3Schristos* Calls to raise() or abort() to programmatically raise a signal are 37*fbb2e0a3Schristos not detected by libuv; these will not trigger a signal watcher. 38*fbb2e0a3Schristos 39*fbb2e0a3Schristos.. versionchanged:: 1.15.0 SIGWINCH support on Windows was improved. 40*fbb2e0a3Schristos.. versionchanged:: 1.31.0 32-bit libuv SIGWINCH support on 64-bit Windows was 41*fbb2e0a3Schristos rolled back to old implementation. 42*fbb2e0a3Schristos 43*fbb2e0a3SchristosUnix notes 44*fbb2e0a3Schristos---------- 45*fbb2e0a3Schristos 46*fbb2e0a3Schristos* SIGKILL and SIGSTOP are impossible to catch. 47*fbb2e0a3Schristos 48*fbb2e0a3Schristos* Handling SIGBUS, SIGFPE, SIGILL or SIGSEGV via libuv results into undefined behavior. 49*fbb2e0a3Schristos 50*fbb2e0a3Schristos* SIGABRT will not be caught by libuv if generated by `abort()`, e.g. through `assert()`. 51*fbb2e0a3Schristos 52*fbb2e0a3Schristos* On Linux SIGRT0 and SIGRT1 (signals 32 and 33) are used by the NPTL pthreads library to 53*fbb2e0a3Schristos manage threads. Installing watchers for those signals will lead to unpredictable behavior 54*fbb2e0a3Schristos and is strongly discouraged. Future versions of libuv may simply reject them. 55*fbb2e0a3Schristos 56*fbb2e0a3Schristos 57*fbb2e0a3SchristosData types 58*fbb2e0a3Schristos---------- 59*fbb2e0a3Schristos 60*fbb2e0a3Schristos.. c:type:: uv_signal_t 61*fbb2e0a3Schristos 62*fbb2e0a3Schristos Signal handle type. 63*fbb2e0a3Schristos 64*fbb2e0a3Schristos.. c:type:: void (*uv_signal_cb)(uv_signal_t* handle, int signum) 65*fbb2e0a3Schristos 66*fbb2e0a3Schristos Type definition for callback passed to :c:func:`uv_signal_start`. 67*fbb2e0a3Schristos 68*fbb2e0a3Schristos 69*fbb2e0a3SchristosPublic members 70*fbb2e0a3Schristos^^^^^^^^^^^^^^ 71*fbb2e0a3Schristos 72*fbb2e0a3Schristos.. c:member:: int uv_signal_t.signum 73*fbb2e0a3Schristos 74*fbb2e0a3Schristos Signal being monitored by this handle. Readonly. 75*fbb2e0a3Schristos 76*fbb2e0a3Schristos.. seealso:: The :c:type:`uv_handle_t` members also apply. 77*fbb2e0a3Schristos 78*fbb2e0a3Schristos 79*fbb2e0a3SchristosAPI 80*fbb2e0a3Schristos--- 81*fbb2e0a3Schristos 82*fbb2e0a3Schristos.. c:function:: int uv_signal_init(uv_loop_t* loop, uv_signal_t* signal) 83*fbb2e0a3Schristos 84*fbb2e0a3Schristos Initialize the handle. 85*fbb2e0a3Schristos 86*fbb2e0a3Schristos.. c:function:: int uv_signal_start(uv_signal_t* signal, uv_signal_cb cb, int signum) 87*fbb2e0a3Schristos 88*fbb2e0a3Schristos Start the handle with the given callback, watching for the given signal. 89*fbb2e0a3Schristos 90*fbb2e0a3Schristos.. c:function:: int uv_signal_start_oneshot(uv_signal_t* signal, uv_signal_cb cb, int signum) 91*fbb2e0a3Schristos 92*fbb2e0a3Schristos .. versionadded:: 1.12.0 93*fbb2e0a3Schristos 94*fbb2e0a3Schristos Same functionality as :c:func:`uv_signal_start` but the signal handler is reset the moment 95*fbb2e0a3Schristos the signal is received. 96*fbb2e0a3Schristos 97*fbb2e0a3Schristos.. c:function:: int uv_signal_stop(uv_signal_t* signal) 98*fbb2e0a3Schristos 99*fbb2e0a3Schristos Stop the handle, the callback will no longer be called. 100*fbb2e0a3Schristos 101*fbb2e0a3Schristos.. seealso:: The :c:type:`uv_handle_t` API functions also apply. 102