A simple wrapper for handling Unix process signals.
extern crate simple_signal;
use simple_signal::{self, Signal};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
fn main() {
let running = Arc::new(AtomicBool::new(true));
let r = running.clone();
simple_signal::set_handler(&[Signal::Int, Signal::Term], move |_signals| {
r.store(false, Ordering::SeqCst);
});
println!("Waiting for a signal...");
while running.load(Ordering::SeqCst) {}
println!("Got it! Exiting...");
}
cargo run --example readme_example
If you're using a nightly compiler, I suggest building with cargo build --features nightly
to avoid the dependency on lazy_static. On stable and beta compilers, just run cargo build
.