Module Core__.Signal.Expert

The Expert module contains functions that novice users should avoid, due to their complexity.

An OCaml signal handler can run at any time, which introduces all the semantic complexities of multithreading. It is much easier to use Async's signal handling, see Async_unix.Signal, which does not involve multithreading, and runs user code as ordinary Async jobs. Also, beware that there can only be a single OCaml signal handler for any signal, so handling a signal with a Core signal handler will interfere if Async is attempting to handle the same signal.

All signal handler functions are called with Exn.handle_uncaught_and_exit, to prevent the signal handler from raising, because raising from a signal handler could raise to any allocation or GC point in any thread, which would be impossible to reason about.

If you do use Core signal handlers, you should strive to make the signal handler perform a simple idempotent action, like setting a ref.

type behavior = [
| `Default
| `Ignore
| `Handle of t ‑> unit
]
val signal : t ‑> behavior ‑> behavior

signal t sets the behavior of the system on receipt of signal t and returns the behavior previously associated with t. If t is not available on your system, signal raises.

val set : t ‑> behavior ‑> unit

set t b is ignore (signal t b).

val handle : t ‑> (t ‑> unit) ‑> unit

handle t f is set t (`Handle f).