This crate provies experimental support for responding to OS signals using channels. Currently, this only works on Unix based systems, but I'd appreciate help adding Windows support.
Dual-licensed under MIT or the UNLICENSE.
Documentation
http://burntsushi.net/rustdoc/chan_signal/.
Example
Use is really simple. Just ask the chan_signal
crate to create a channel
subscribed to a set of signals. When a signal is sent to the process it will
be delivered to the channel.
use Signal;
let signal = notify;
// Blocks until this process is sent an INT or TERM signal.
// Since the channel is never closed, we can unwrap the received value.
signal.recv.unwrap;
A realer example
When combined with chan_select!
from the chan
crate, one can easily
integrate signals with the rest of your program. For example, consider a
main function that waits for either normal completion of work (which is done
in a separate thread) or for a signal to be delivered:
extern crate chan;
extern crate chan_signal;
use Signal;
How it works
TL;DR - Spawn a thread, block on sigwait
, deliver signals, repeat.