package async_unix

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Async_unix.SignalSource

Signal handling.

To discourage use of the Signal.Expert module, we hide it here. People can use Core.Signal.Expert if they need.

include module type of Core.Signal with type t = Core.Signal.t with module Expert := Core.Signal.Expert
include Bin_prot.Binable.S with type t := t
include Bin_prot.Binable.S_only_functions with type t := t
Sourceval bin_size_t : t Bin_prot.Size.sizer
Sourceval bin_write_t : t Bin_prot.Write.writer
Sourceval bin_read_t : t Bin_prot.Read.reader
Sourceval __bin_read_t__ : (int -> t) Bin_prot.Read.reader

This function only needs implementation if t exposed to be a polymorphic variant. Despite what the type reads, this does *not* produce a function after reading; instead it takes the constructor tag (int) before reading and reads the rest of the variant t afterwards.

Sourceval bin_shape_t : Bin_prot.Shape.t
include Sexplib0.Sexpable.S with type t := t
Sourceval t_of_sexp : Sexplib0.Sexp.t -> t
Sourceval sexp_of_t : t -> Sexplib0.Sexp.t
include Core.Comparable.S with type t := t
include Base.Comparable.S with type t := t
include Base.Comparisons.S with type t := t
include Base.Comparisons.Infix with type t := t
Sourceval (>=) : t -> t -> bool
Sourceval (<=) : t -> t -> bool
Sourceval (=) : t -> t -> bool
Sourceval (>) : t -> t -> bool
Sourceval (<) : t -> t -> bool
Sourceval (<>) : t -> t -> bool
Sourceval min : t -> t -> t
Sourceval max : t -> t -> t
Sourceval ascending : t -> t -> int

ascending is identical to compare. descending x y = ascending y x. These are intended to be mnemonic when used like List.sort ~compare:ascending and List.sort ~cmp:descending, since they cause the list to be sorted in ascending or descending order, respectively.

Sourceval descending : t -> t -> int
Sourceval between : t -> low:t -> high:t -> bool

between t ~low ~high means low <= t <= high

Sourceval clamp_exn : t -> min:t -> max:t -> t

clamp_exn t ~min ~max returns t', the closest value to t such that between t' ~low:min ~high:max is true.

Raises if not (min <= max).

Sourceval clamp : t -> min:t -> max:t -> t Base.Or_error.t
include Base.Comparator.S with type t := t
Sourcetype comparator_witness = Core.Signal.comparator_witness
Sourceval validate_lbound : min:t Core.Maybe_bound.t -> t Validate.check
Sourceval validate_ubound : max:t Core.Maybe_bound.t -> t Validate.check
Sourceval validate_bound : min:t Core.Maybe_bound.t -> max:t Core.Maybe_bound.t -> t Validate.check
Sourcemodule Replace_polymorphic_compare = Core.Signal.Replace_polymorphic_compare
include Core.Hashable.S with type t := t
include Ppx_compare_lib.Comparable.S with type t := t
Sourceval compare : t -> t -> int
include Ppx_hash_lib.Hashable.S with type t := t
Sourceval hash_fold_t : Base.Hash.state -> t -> Base.Hash.state
Sourceval hashable : t Base.Hashable.t
Sourcemodule Hash_set = Core.Signal.Hash_set
Sourcemodule Hash_queue = Core.Signal.Hash_queue
include Base.Stringable.S with type t := t
Sourceval of_string : string -> t
Sourceval equal : t -> t -> Base.Bool.t
Sourceval of_caml_int : Base.Int.t -> t

of_caml_int constructs a Signal.t given an OCaml internal signal number. This is only for the use of the Core_unix module.

Sourceval to_caml_int : t -> Base.Int.t
Sourceval to_string : t -> Base.String.t

to_string t returns a human-readable name: "sigabrt", "sigalrm", ...

Sourcetype sys_behavior = [
  1. | `Continue
    (*

    Continue the process if it is currently stopped

    *)
  2. | `Dump_core
    (*

    Terminate the process and dump core

    *)
  3. | `Ignore
    (*

    Ignore the signal

    *)
  4. | `Stop
    (*

    Stop (suspend) the process

    *)
  5. | `Terminate
    (*

    Terminate the process

    *)
]

The behaviour of the system if a signal is received by a process. See include/linux/kernel.h in the Linux kernel source tree (not the file /usr/include/linux/kernel.h).

Sourceval sexp_of_sys_behavior : sys_behavior -> Sexplib0.Sexp.t
Sourceval sys_behavior_of_sexp : Sexplib0.Sexp.t -> sys_behavior
Sourceval __sys_behavior_of_sexp__ : Sexplib0.Sexp.t -> sys_behavior
Sourceval default_sys_behavior : t -> sys_behavior

Queries the default system behavior for a signal.

Specific signals, along with their default behavior and meaning.

Sourceval abrt : t

Dump_core Abnormal termination

Sourceval alrm : t

Terminate Timeout

Sourceval bus : t

Dump_core Bus error

Sourceval chld : t

Ignore Child process terminated

Sourceval cont : t

Continue Continue

Sourceval fpe : t

Dump_core Arithmetic exception

Sourceval hup : t

Terminate Hangup on controlling terminal

Sourceval ill : t

Dump_core Invalid hardware instruction

Sourceval int : t

Terminate Interactive interrupt (ctrl-C)

Sourceval kill : t

Terminate Termination (cannot be ignored)

Sourceval pipe : t

Terminate Broken pipe

Sourceval poll : t

Terminate Pollable event

Sourceval prof : t

Terminate Profiling interrupt

Sourceval quit : t

Dump_core Interactive termination

Sourceval segv : t

Dump_core Invalid memory reference

Sourceval sys : t

Dump_core Bad argument to routine

Sourceval stop : t

Stop Stop

Sourceval term : t

Terminate Termination

Sourceval trap : t

Dump_core Trace/breakpoint trap

Sourceval tstp : t

Stop Interactive stop

Sourceval ttin : t

Stop Terminal read from background process

Sourceval ttou : t

Stop Terminal write from background process

Sourceval urg : t

Ignore Urgent condition on socket

Sourceval usr1 : t

Terminate Application-defined signal 1

Sourceval usr2 : t

Terminate Application-defined signal 2

Sourceval vtalrm : t

Terminate Timeout in virtual time

Sourceval xcpu : t

Dump_core Timeout in cpu time

Sourceval xfsz : t

Dump_core File size limit exceeded

Sourceval zero : t

Ignore No-op; can be used to test whether the target process exists and the current process has permission to signal it

Sourcetype pid_spec = [
  1. | `Use_Signal_unix
]
  • deprecated [since 2021-04] Use [Signal_unix]
Sourcetype sigprocmask_command = [
  1. | `Use_Signal_unix
]
  • deprecated [since 2021-04] Use [Signal_unix]
Sourceval can_send_to : [ `Use_Signal_unix ]
  • deprecated [since 2021-04] Use [Signal_unix]
Sourceval of_system_int : [ `Use_Signal_unix ]
  • deprecated [since 2021-04] Use [Signal_unix]
Sourceval send : [ `Use_Signal_unix ]
  • deprecated [since 2021-04] Use [Signal_unix]
Sourceval send_exn : [ `Use_Signal_unix ]
  • deprecated [since 2021-04] Use [Signal_unix]
Sourceval send_i : [ `Use_Signal_unix ]
  • deprecated [since 2021-04] Use [Signal_unix]
Sourceval sexp_of_pid_spec : [ `Use_Signal_unix ]
  • deprecated [since 2021-04] Use [Signal_unix]
Sourceval sigpending : [ `Use_Signal_unix ]
  • deprecated [since 2021-04] Use [Signal_unix]
Sourceval sigprocmask : [ `Use_Signal_unix ]
  • deprecated [since 2021-04] Use [Signal_unix]
Sourceval sigsuspend : [ `Use_Signal_unix ]
  • deprecated [since 2021-04] Use [Signal_unix]
Sourceval to_system_int : [ `Use_Signal_unix ]
  • deprecated [since 2021-04] Use [Signal_unix]
Sourcemodule Stable = Core.Signal.Stable
Sourceval handle_default : [ `Do_not_use_with_async ] -> _

We override values from Core.Signal that we don't want people to use with Async.

Sourceval ignore : [ `Do_not_use_with_async ] -> _
Sourceval handle : ?stop:unit Async_kernel.Deferred.t -> t list -> f:(t -> unit) -> unit

handle ?stop signals ~f arranges so that whenever a signal in signals is delivered, f is called on that signal. If f raises, then an exception will be raised to the monitor in effect when handle was called.

Multiple calls to handle with the same signal will cause all the handlers to run when that signal is delivered, not just the last handler from the last call to handle.

The first time handle is called for a signal, it will install a C signal handler for it, replacing the existing C signal handler for that signal.

If stop is passed, the Async signal handler will be uninstalled when stop resolves. (the OCaml and C signal handlers are never uninstalled, so if this is the last Async signal handler then the signal will start being ignored)

Sourceval manage_by_async : t list -> unit

manage_by_async signal arranges so that signal starts being managed by Async, i.e. we install an OCaml signal handler for it. The behavior of that handler approximates the default signal behavior with the difference that for signals whose default behavior is to terminate the program, we run on-shutdown handlers first.

For terminating signals the exit status of the program will be indistinguishable from the signal not being handled. (see Shutdown.shutdown_with_signal_exn)

If handle is called (before or after), that takes precedence: the shutdown on signal behavior is suppressed (even if the corresponding stop ivar is determined).

Sourceval terminating : t list

terminating is a list of signals that can be supplied to handle and whose default behavior is to terminate the program: alrm hup int term usr1 usr2.

Various signals whose default_sys_behavior is `Terminate are not included:

   | kill   | it's not allowed to be handled                            |
   | pipe   | Async already ignores this signal, since it handles EPIPE |
   | prof   | so that we can profile things with -p                     |
   | vtalrm | it already has a handler                                  |
Sourceval is_managed_by_async : t -> bool

is_managed_by_async signal returns true iff signal is being managed by Async, and hence its default behavior is no longer in effect.

OCaml

Innovation. Community. Security.