12 stable releases (3 major)

3.1.1 Jun 5, 2018
3.1.0 Jan 14, 2018
3.0.3 Oct 7, 2017
3.0.2 May 29, 2017
0.1.1 Jul 16, 2015

#3 in Memory management

Download history 1872/week @ 2018-05-27 1885/week @ 2018-06-03 3185/week @ 2018-06-10 2927/week @ 2018-06-17 3359/week @ 2018-06-24 3270/week @ 2018-07-01 4069/week @ 2018-07-08 3897/week @ 2018-07-15 3188/week @ 2018-07-22 4334/week @ 2018-07-29 3219/week @ 2018-08-05 3432/week @ 2018-08-12 2748/week @ 2018-08-19

8,991 downloads per month
Used in 47 crates (42 directly)

MIT/Apache

24KB
396 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 && target/debug/example/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

~772KB

  • unix nix 0.11
  • windows winapi 0.3+consoleapi+handleapi+synchapi+winbase