Rust Signal handling Handling signals with nix crate.

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

The nix crate provides an UNIX Rust API to handle signals, however it requires using unsafe rust so you should be careful.

use nix::sys::signal;

extern fn handle_sigint(_:i32) {
    // Be careful here...
}

fn main() {
    let sig_action = signal::SigAction::new(handle_sigint,
                                          signal::SockFlag::empty(),
                                          signal::SigSet::empty());
    signal::sigaction(signal::SIGINT, &sig_action);
}


Got any Rust Question?