package eio

  1. Overview
  2. Docs
Effect-based direct-style IO API for OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

eio-0.9.tbz
sha256=cfbdf92e480063333f9c6ab234ee46aceeadb3209744c801cdf8a274b1997d99
sha512=410e334103a9ae9805c57ad12ca9726b0b74b82cca4477004521ccfcc7ddb0f63ec6f38fdd69728792d3dff1ab3f8ad990cd6b02b45f467cf492e2840941c669

doc/eio.unix/Eio_unix/Private/Fork_action/index.html

Module Private.Fork_actionSource

Actions to perform after forking a child process.

To spawn a child executable on Unix, the parent forks a copy of itself, then has the child copy set up the environment for the new program and execute it.

However, we cannot run any OCaml code in the forked child process. This is because `fork` only duplicates its own domain. To the child, it appears that all other domains have stopped responding and if it tries to e.g. perform a GC then the child process will hang.

Therefore, the fork call and all child actions need to be written in C. This module provides some support code for doing that. Individual backends will wrap these actions with higher-level APIs and can also add their own platform-specific actions

Sourcetype fork_fn

A C function, as defined in "include/fork_action.h".

Sourcetype c_action = Obj.t

An action to be performed in a child process after forking. This must be a tuple whose first field is a fork_fn.

Sourcetype t = {
  1. run : 'a. (c_action -> 'a) -> 'a;
}

An action that calls run k in the parent process to create the C action. run passes the action to k, which forks the child and runs it. When k returns, run can free any resources used.

Sourceval with_actions : t list -> (c_action list -> 'a) -> 'a

Actions

Sourceval execve : string -> argv:string array -> env:string array -> t

See execve(2).

Sourceval chdir : string -> t

chdir path changes directory to path.

Sourceval fchdir : Eio_unix__.Rcfd.t -> t

fchdir fd changes directory to fd.

Sourcetype blocking = [
  1. | `Blocking
    (*

    Clear the O_NONBLOCK flag in the child process.

    *)
  2. | `Nonblocking
    (*

    Set the O_NONBLOCK flag in the child process.

    *)
  3. | `Preserve_blocking
    (*

    Don't change the blocking mode of the FD.

    *)
]
Sourceval inherit_fds : (int * Eio_unix__.Rcfd.t * [< blocking ]) list -> t

inherit_fds mapping marks file descriptors as not close-on-exec and renumbers them.

For each (fd, src, flags) in mapping, we use dup2 to duplicate src as fd. If there are cycles in mapping, a temporary FD is used to break the cycle. A mapping from an FD to itself simply clears the close-on-exec flag.

After this, the new FDs may also be set as blocking or non-blocking, depending on flags.

OCaml

Innovation. Community. Security.

On This Page
  1. Actions