sigildocs

(sigil signals)

(sigil signals) - POSIX Signal Handling

Register Scheme callbacks for OS signals (SIGTERM, SIGINT, etc.). Signal handlers run in scheduler context during the poll cycle, so they are safe to call arbitrary Scheme code.

Usage

(import (sigil signals))

(on-signal 'term (lambda () (cleanup!) (exit 0)))
(on-signal 'usr1 (lambda () (reload-config!)))

Supported signals: term, int, hup, usr1, usr2, winch

Exports

on-signalprocedure

Register a callback for a POSIX signal.

Installs a C-level signal handler that sets a volatile flag, and registers the Scheme callback to be invoked when the signal is detected during the scheduler poll cycle.

Supported signal names: term, int, hup, usr1, usr2, winch

(on-signal 'term (lambda () (display "shutting down\n")))

Check all registered signals and invoke pending handlers.

Called by the async scheduler after each poll cycle. Safe to call from Scheme context. Each pending signal's handler is invoked once, then the flag is cleared.