Rust Signal handling Handling signals with nix crate.


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