Module: sys.signal
Source: ./sys/signal.reef
Overview
sys/signal - Signal handling
Provides Unix signal handling capabilities. Signals are used for inter-process communication and handling events like Ctrl+C.
Example - Handle SIGINT (Ctrl+C): signal_handle(SIGINT()) while true if signal_received(SIGINT()) println("Caught Ctrl+C, exiting...") break end if // Do work... end while
Example - Ignore SIGPIPE: signal_ignore(SIGPIPE())
Functions
fn SIGINT(): int
Signal constant functions
fn SIGTERM(): int
fn SIGHUP(): int
fn SIGQUIT(): int
fn SIGKILL(): int
fn SIGSTOP(): int
fn SIGCONT(): int
fn SIGCHLD(): int
fn SIGUSR1(): int
fn SIGUSR2(): int
fn SIGPIPE(): int
fn SIGALRM(): int
fn signal_handle(signum: int): bool
Register to handle a signal (sets a flag when received) Returns true on success NOTE: SIGURG is reserved for GC suspension -- installing a handler for it here would override the collector's own handler, so this returns false for SIGURG instead.
fn signal_ignore(signum: int): bool
Ignore a signal Returns true on success NOTE: ignoring SIGURG would break GC suspension; refused.
fn signal_default(signum: int): bool
Reset signal to default behavior Returns true on success NOTE: resetting SIGURG to default would break GC suspension; refused.
fn signal_received(signum: int): bool
Check if signal was received (clears the flag) Returns true if signal was received since last check
fn signal_name(signum: int): string
Get the name of a signal
fn SIGRTMIN(): int
SIGRTMIN constant (real-time signal base)
fn SIGRTMIN_offset(n: int): int
SIGRTMIN + offset
fn signal_block(signum: int): bool
Block a signal (prevent delivery) NOTE: SIGURG is reserved by the runtime as the GC stop-the-world suspension channel. Calling this with SIGURG returns false (the underlying reef_signal_block refuses it with EINVAL) rather than blocking it, since that would hang the collector.
fn signal_unblock(signum: int): bool
Unblock a signal (allow delivery) SIGURG is NOT refused here -- unblocking it is always safe.
fn signal_wait(signals: [int]): int
Wait for one of a set of signals
Returns the signal number received
NOTE: if SIGURG is included in signals, this returns -1
(EINVAL) instead of waiting -- sigwait()ing on SIGURG could consume a
GC-suspend signal meant for the collector.
fn selfpipe_create(): [int]
Create a self-pipe for async-signal-safe signal delivery Returns [read_fd, write_fd]
fn selfpipe_register(signum: int, write_fd: int): bool
Register a signal to write to self-pipe WARNING: Do not register GC signals (SIGUSR1/SIGUSR2 or SIGRTMIN+0/1)
fn selfpipe_read(read_fd: int): int
Read a signal number from self-pipe Returns signal number, or -1 if pipe is empty
Procedures
proc signal_init()
Initialize signal handling system
Generated by reefc doc