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!
1 Introduction
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 dangerous, as the code here will conflict with the code in Racket itself.
2 What to require
All the functionality below can be accessed with a single require:
(require unix-signals) | package: unix-signals |
This library represents signal names as symbols all in upper-case; for example, 'SIGUSR1 and 'SIGKILL.
2.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?)
procedure
(ignore-signal! sig) → boolean?
sig : (or/c fixnum? symbol?)
procedure
(release-signal! sig) → boolean?
sig : (or/c fixnum? symbol?)
value
procedure
(read-signal) → fixnum?
2.2 Sending a signal
This library provides getpid from racket/os for convenience.
2.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?