Easy unix signals handler for Rust projects
Clone or download
Pull request Compare This branch is 19 commits ahead, 74 commits behind Detegr:master.
Latest commit 19d8577 Mar 21, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples More clean-up. Nov 11, 2016
src More clean-up. Nov 11, 2016
.gitignore rust-ctrlc -> rust-simple-signal Dec 4, 2015
.travis.yml Added stable and beta to travis.yml Jul 16, 2015
Cargo.toml bump version Mar 21, 2018
README.md More clean-up. Nov 11, 2016



A simple wrapper for handling Unix process signals.

Example Usage

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...");

Try the example yourself

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.