fn kill_politely(child: &mut Child, wait: Duration) {
    use nix::{
        sys::{
            signal::{self, Signal},
            wait::waitpid,
        },
        unistd::Pid,
    };

    let pid = Pid::from_raw(child.id().try_into().unwrap());

    // try to be polite
    let wait_errored = match signal::kill(pid, Signal::SIGTERM) {
        Ok(()) => wait_timeout(pid, wait).is_err(),
        Err(e) => {
            info!("Error sending SIGTERM to child: {e}");
            true
        }
    };

    if wait_errored {
        // timeout => kill it
        info!("Cannot terminate child politely, using SIGKILL...");

        if let Err(e) = signal::kill(pid, Signal::SIGKILL) {
            info!("Error sending SIGKILL to child: {e}");
        }
        if let Err(e) = waitpid(pid, None) {
            info!("Cannot wait for child: {e}");
        }
    } else {
        info!("Killed child politely");
    }
}
/// Attempt to kill a child process politely.
Attempt to kill a child process politely.
Attempt to kill a child process politely .
fn kill_politely(child: &mut Child, wait: Duration) {
    use nix::{
        sys::{
            signal::{self, Signal},
            wait::waitpid,
        },
        unistd::Pid,
    };
    let pid = Pid::from_raw(child.id().try_into().unwrap());
    // try to be polite
    let wait_errored = match signal::kill(pid, Signal::SIGTERM) {
        Ok(()) => wait_timeout(pid, wait).is_err(),
        Err(e) => {
            info!("Error sending SIGTERM to child: {e}");
            true
        }
    };
    if wait_errored {
        // timeout => kill it
        info!("Cannot terminate child politely, using SIGKILL...");
        if let Err(e) = signal::kill(pid, Signal::SIGKILL) {
            info!("Error sending SIGKILL to child: {e}");
        }
        if let Err(e) = waitpid(pid, None) {
            info!("Cannot wait for child: {e}");
        }
    } else {
        info!("Killed child politely");
    }
}
fn kill_politely ( child : & mut Child , wait : Duration ) { use nix :: { sys :: { signal :: { self , Signal } , wait :: waitpid , } , unistd :: Pid , } ; let pid = Pid :: from_raw ( child . id ( ) . try_into ( ) . unwrap ( ) ) ; // try to be polite let wait_errored = match signal :: kill ( pid , Signal :: SIGTERM ) { Ok ( ( ) ) => wait_timeout ( pid , wait ) . is_err ( ) , Err ( e ) => { info ! ( " " ) ; true } } ; if wait_errored { // timeout => kill it info ! ( " " ) ; if let Err ( e ) = signal :: kill ( pid , Signal :: SIGKILL ) { info ! ( " " ) ; } if let Err ( e ) = waitpid ( pid , None ) { info ! ( " " ) ; } } else { info ! ( " " ) ; } }
Attempt to kill a child process politely.
Attempt to kill a child process politely .
child
&mut Child
wait
Duration
child
&mut Child
wait
Duration