Skip to main content

Module signal

Module signal 

Source
Expand description

Signal delivery and the signal exit-code convention.

Both runners stop processes the same way, so the signal vocabulary lives in one place instead of being duplicated per runner:

The model mirrors the JavaScript implementation:

  1. The requested signal is delivered to the child and its process group, so grandchildren spawned by a shell are stopped too. The group is skipped for a child that shares the caller’s terminal, which stays in the caller’s process group by design so that CTRL+C keeps reaching it.
  2. The child is given a grace period (DEFAULT_KILL_GRACE_MS) to run its own signal handler and exit on its own terms.
  3. If it is still alive when the grace period expires, SIGKILL follows, so a process that ignores the signal still terminates.
  4. The reported exit code is the conventional 128 + signal value (signal_exit_code).

A grace period of zero collapses steps 1 to 3 into SIGKILL alone: any work between the requested signal and the escalation is a window the child can be scheduled in, so delivering it first would make “no grace” a race rather than a guarantee. The exit code still reflects the signal that was asked for.

Windows stops the tree immediately with taskkill /PID <pid> /T /F before the parent exits. There is no POSIX signal handler or grace period there; the caller falls back to terminating the direct child if taskkill fails.

Constants§

DEFAULT_KILL_GRACE_MS
Default grace period (in milliseconds) between the requested signal and the forceful SIGKILL escalation.
DEFAULT_KILL_SIGNAL
Default signal used to stop a process when no explicit signal is given.

Functions§

signal_exit_code
The exit code reported for a process stopped with signal, following the conventional 128 + signal mapping used by POSIX shells.
signal_number
Map a signal name to its numeric value.