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