unix-signals
(require unix-signals) | package: unix-signals |
If you find that this library lacks some feature you need, or you have a suggestion for improving it, please don’t hesitate to get in touch with me!
This library provides a means of sending and receiving Unix signals to Racket programs.
Be warned that attempting to receive certain signals used by the Racket runtime is unsafe, as the code here will conflict with the code in Racket itself.
1 Waiting for a signal
To receive Unix signals using this library, call capture-signal! once for each signal of interest, and then use next-signal-evt or read-signal. Use ignore-signal! and release-signal! to ignore a signal (SIG_IGN) or to install the default signal-handler (SIG_DFL), respectively.
(require unix-signals) (capture-signal! 'SIGUSR1) (capture-signal! 'SIGUSR2) (printf "Try 'kill -USR1 ~a' and 'kill -USR2 ~a'\n" (getpid) (getpid)) (let loop () (define signum (read-signal)) (printf "Received signal ~v (name ~v)\n" signum (lookup-signal-name signum)) (loop))
Calls to capture-signal! and friends have global effect within the Racket process. Likewise, use of next-signal-evt and read-signal have global side-effects on the state of the Racket process.
procedure
(capture-signal! sig) → boolean?
sig : (or/c fixnum? symbol?)
Note that this function is unsafe: it can corrupt or crash the Racket runtime system.
procedure
(ignore-signal! sig) → boolean?
sig : (or/c fixnum? symbol?)
Note that this function is unsafe: it can corrupt or crash the Racket runtime system.
procedure
(release-signal! sig) → boolean?
sig : (or/c fixnum? symbol?)
Note that this function is unsafe: it can corrupt or crash the Racket runtime system.
value
procedure
(read-signal) → fixnum?
2 Sending a signal
Note that this function is unsafe: it can corrupt or crash the Racket runtime system.
For convenience, this library also re-exports getpid from racket/os.
3 Mapping between signal names and signal numbers
procedure
(lookup-signal-number sym) → (opt/c fixnum?)
sym : symbol?
procedure
(lookup-signal-name num) → (opt/c symbol?)
num : fixnum?