Skip to content

A simple crate to catch signals and set a boolean flag for later use.

License

Notifications You must be signed in to change notification settings

lilydjwg/rust-signalbool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple crate to catch signals and set a boolean flag for later use.

This crate doesn't create threads behind the scene.

Crates.io Version GitHub stars

Example

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;
      }
    }
  }
}

About

A simple crate to catch signals and set a boolean flag for later use.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages