Function fork

Synopsis

#include <src/uvw/loop.h>

void fork() noexcept

Description

Reinitialize any kernel state necessary in the child process after a fork(2) system call.

Previously started watchers will continue to be started in the child process.

It is necessary to explicitly call this function on every event loop created in the parent process that you plan to continue to use in the child, including the default loop (even if you don’t continue to use it in the parent). This function must be called before calling any API function using the loop in the child. Failure to do so will result in undefined behaviour, possibly including duplicate events delivered to both parent and child or aborting the child process.

When possible, it is preferred to create a new loop in the child process instead of reusing a loop created in the parent. New loops created in the child process after the fork should not use this function.

Note that this function is not implemented on Windows.
Note also that this function is experimental in libuv. It may contain bugs, and is subject to change or removal. API and ABI stability is not guaranteed.

An ErrorEvent will be emitted in case of errors.

See the official documentation for further details.

Source

Lines 115-121 in src/uvw/loop.cpp. Line 363 in src/uvw/loop.h.

UVW_INLINE void Loop::fork() noexcept {
    auto err = uv_loop_fork(loop.get());

    if(err) {
        publish(ErrorEvent{err});
    }
}





Add Discussion as Guest

Log in