15 stable releases (3 major)

3.1.4 Feb 17, 2020
3.1.3 Jun 6, 2019
3.1.2 Apr 23, 2019
3.1.1 Jun 5, 2018
0.1.1 Jul 16, 2015

#1 in Operating systems

Download history 14520/week @ 2019-12-02 13248/week @ 2019-12-09 13878/week @ 2019-12-16 8037/week @ 2019-12-23 9853/week @ 2019-12-30 14230/week @ 2020-01-06 16043/week @ 2020-01-13 15944/week @ 2020-01-20 15618/week @ 2020-01-27 14861/week @ 2020-02-03 16037/week @ 2020-02-10 15270/week @ 2020-02-17 15983/week @ 2020-02-24 16314/week @ 2020-03-02 16136/week @ 2020-03-09 16980/week @ 2020-03-16

58,507 downloads per month
Used in 142 crates (117 directly)

MIT/Apache

24KB
400 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–265KB