Home Explore Blog CI



neovim

17th chunk of `runtime/doc/luvref.txt`
64f7b41ca08861494c4adf122c5f18466ba83ded712f9fe10000000100000fa9
 uv.signal_start(signal, "sigint", function(signame)
      print("got " .. signame .. ", shutting down")
      os.exit(1)
    end)
<

uv.new_signal()                                                *uv.new_signal()*

                Creates and initializes a new |uv_signal_t|. Returns the Lua
                userdata wrapping it.

                Returns: `uv_signal_t userdata` or `fail`

uv.signal_start({signal}, {signame}, {callback})             *uv.signal_start()*

                > method form `signal:start(signame, callback)`

                Parameters:
                - `signal`: `uv_signal_t userdata`
                - `signame`: `string` or `integer`
                - `callback`: `callable`
                  - `signame`: `string`

                Start the handle with the given callback, watching for the
                given signal.

                See |luv-constants| for supported `signame` input and output
                values.

                Returns: `0` or `fail`
                                                     *uv.signal_start_oneshot()*
uv.signal_start_oneshot({signal}, {signame}, {callback})

                > method form `signal:start_oneshot(signame, callback)`

                Parameters:
                - `signal`: `uv_signal_t userdata`
                - `signame`: `string` or `integer`
                - `callback`: `callable`
                  - `signame`: `string`

                Same functionality as |uv.signal_start()| but the signal
                handler is reset the moment the signal is received.

                See |luv-constants| for supported `signame` input and output
                values.

                Returns: `0` or `fail`

uv.signal_stop({signal})                                      *uv.signal_stop()*

                > method form `signal:stop()`

                Parameters:
                - `signal`: `uv_signal_t userdata`

                Stop the handle, the callback will no longer be called.

                Returns: `0` or `fail`

==============================================================================
`uv_process_t` — Process handle                  *luv-process-handle* *uv_process_t*

> |uv_handle_t| functions also apply.

Process handles will spawn a new process and allow the user to control it and
establish communication channels with it using streams.

uv.disable_stdio_inheritance()                  *uv.disable_stdio_inheritance()*

                Disables inheritance for file descriptors / handles that this
                process inherited from its parent. The effect is that child
                processes spawned by this process don't accidentally inherit
                these handles.

                It is recommended to call this function as early in your
                program as possible, before the inherited file descriptors can
                be closed or duplicated.

                Returns: Nothing.

                Note: This function works on a best-effort basis: there is no
                guarantee that libuv can discover all file descriptors that
                were inherited. In general it does a better job on Windows
                than it does on Unix.

uv.spawn({path}, {options}, {on_exit})                              *uv.spawn()*

                Parameters:
                - `path`: `string`
                - `options`: `table` (see below)
                - `on_exit`: `callable`
                  - `code`: `integer`
                  - `signal`: `integer`

                Initializes the process handle and starts the process. If the
                process is successfully spawned, this function will return the
                handle and pid of the child process.

                Possible reasons for failing to spawn would include (but not
                be limited to) the file to execute not existing, not having
                permissions to use the setuid or setgid specified, or not
                having enough memory to allocate

Title: Libuv: Signal and Process Handling (uv.signal, uv.process)
Summary
This section details libuv's functions for signal and process handling. It describes `uv.new_signal()`, `uv.signal_start()`, `uv.signal_start_oneshot()`, and `uv.signal_stop()` for managing signal handlers, including their parameters and return values. It also introduces `uv_process_t` for process management, including `uv.disable_stdio_inheritance()` and `uv.spawn()`, focusing on preventing file descriptor inheritance and spawning child processes with detailed options and exit callbacks.