17 stable releases (3 major)

Uses old Rust 2015

3.1.6 Jul 29, 2020
3.1.4 Feb 17, 2020
3.1.3 Jun 6, 2019
3.1.1 Jun 5, 2018
0.1.1 Jul 16, 2015

#10 in Operating systems

Download history 19414/week @ 2020-06-09 17461/week @ 2020-06-16 18165/week @ 2020-06-23 18005/week @ 2020-06-30 19485/week @ 2020-07-07 20734/week @ 2020-07-14 23478/week @ 2020-07-21 23797/week @ 2020-07-28 22950/week @ 2020-08-04 24895/week @ 2020-08-11 21113/week @ 2020-08-18 22649/week @ 2020-08-25 21481/week @ 2020-09-01 23759/week @ 2020-09-08 25050/week @ 2020-09-15 23835/week @ 2020-09-22

95,197 downloads per month
Used in 194 crates (162 directly)

MIT/Apache

24KB
404 lines

CtrlC

Build Status Build status

A simple easy to use wrapper around Ctrl-C signal.

Documentation

Example usage

extern crate ctrlc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;

fn main() {
    let running = Arc::new(AtomicBool::new(true));
    let r = running.clone();
    ctrlc::set_handler(move || {
        r.store(false, Ordering::SeqCst);
    }).expect("Error setting Ctrl-C handler");
    println!("Waiting for Ctrl-C...");
    while running.load(Ordering::SeqCst) {}
    println!("Got it! Exiting...");
}

Try the example yourself

cargo build --examples && target/debug/examples/readme_example

Handling SIGTERM

Add CtrlC to Cargo.toml using termination feature and CtrlC will handle both SIGINT and SIGTERM.

[dependencies]
ctrlc = { version = "3.0", features = ["termination"] }

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0–285KB