6 stable releases

Uses old Rust 2015

1.1.1 Mar 21, 2018
1.1.0 Nov 11, 2016
1.0.6 Jun 11, 2016
1.0.5 Mar 1, 2016
1.0.4 Dec 4, 2015

#344 in Operating systems

Download history 3448/week @ 2023-12-16 2539/week @ 2023-12-23 3705/week @ 2023-12-30 3868/week @ 2024-01-06 3450/week @ 2024-01-13 3106/week @ 2024-01-20 3803/week @ 2024-01-27 4623/week @ 2024-02-03 4289/week @ 2024-02-10 3139/week @ 2024-02-17 4635/week @ 2024-02-24 5208/week @ 2024-03-02 5505/week @ 2024-03-09 6850/week @ 2024-03-16 6775/week @ 2024-03-23 4509/week @ 2024-03-30

24,664 downloads per month
Used in 11 crates

MIT license

9KB
159 lines

simple-signal

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

Building

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.


lib.rs:

A simple wrapper for handling Unix process signals.

Dependencies

~46KB