Created
July 11, 2017 02:37
-
-
Save jackpot51/0802c06202f5499c9141c9122246b9fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate syscall; | |
use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering}; | |
static RUNNING: AtomicBool = ATOMIC_BOOL_INIT; | |
extern "C" fn handler(sig: usize) { | |
println!("handler: signal {:X}", sig); | |
RUNNING.store(false, Ordering::SeqCst); | |
} | |
fn main() { | |
let mut action = syscall::data::SigAction::default(); | |
action.sa_handler = handler; | |
let mut old_action = syscall::data::SigAction::default(); | |
syscall::sigaction(syscall::flag::SIGINT, &action, &mut old_action).unwrap(); | |
println!("sigaction {:X}, {:?} => {:?}", syscall::flag::SIGINT, old_action, action); | |
RUNNING.store(true, Ordering::SeqCst); | |
syscall::kill(syscall::getpid().unwrap(), syscall::flag::SIGINT).unwrap(); | |
while RUNNING.load(Ordering::SeqCst) { | |
std::thread::sleep(std::time::Duration::new(5, 0)); | |
} | |
println!("Exiting"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment