Created
April 4, 2021 16:12
-
-
Save jelford/d5afa01dc0f9c455d4effa4f51445d98 to your computer and use it in GitHub Desktop.
Signal-Handling-Raw
This file contains 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
[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" |
This file contains 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
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