Skip to content

Instantly share code, notes, and snippets.

@jelford
Created April 4, 2021 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jelford/d5afa01dc0f9c455d4effa4f51445d98 to your computer and use it in GitHub Desktop.
Save jelford/d5afa01dc0f9c455d4effa4f51445d98 to your computer and use it in GitHub Desktop.
Signal-Handling-Raw
[package]
name = "example"
version = "0.1.0"
authors = ["James Elford <james.p.elford@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
libc = "0.2"
[[bin]]
name = "example"
path = "main.rs"
use std::time::Duration;
extern "C" fn handle_interrupt(_sig: libc::c_int) {
println!("Sorry we didn't get the chance to finish");
}
fn main() {
println!("Hello");
unsafe {
libc::signal(libc::SIGINT, handle_interrupt as libc::sighandler_t);
}
std::thread::sleep(Duration::from_secs(10));
println!("Goodbye");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment