Crates.io | signalbool |
lib.rs | signalbool |
version | 0.2.5 |
source | src |
created_at | 2017-05-27 08:00:13.174169 |
updated_at | 2022-06-21 13:31:13.422537 |
description | A simple crate to catch signals and set a boolean flag for later use. |
homepage | https://github.com/lilydjwg/rust-signalbool |
repository | https://github.com/lilydjwg/rust-signalbool |
max_upload_size | |
id | 16474 |
size | 11,466 |
A simple crate to catch signals and set a boolean flag for later use.
This crate doesn't create threads behind the scene.
Here is a program that sleeps until it receives three SIGINT
signals.
extern crate signalbool;
extern crate nix;
use nix::unistd::sleep;
fn main() {
let mut sb = signalbool::SignalBool::new(
&[signalbool::Signal::SIGINT], signalbool::Flag::Interrupt,
).unwrap();
let mut count = 0;
loop {
sleep(10);
if sb.caught() {
println!("Caught SIGINT.");
count += 1;
sb.reset();
if count == 3 {
break;
}
}
}
}