/// Wait for given PID to exit with a timeout.
Wait for given PID to exit with a timeout.
Wait for given PID to exit with a timeout .
fn wait_timeout(pid: nix::unistd::Pid, timeout: Duration) -> Result<(), ()> {
    use nix::sys::wait::waitpid;
    // use some thread and channel trickery, see https://stackoverflow.com/a/42720480
    let (sender, receiver) = std::sync::mpsc::channel();
    std::thread::spawn(move || {
        let waitpid_res = waitpid(pid, None).map(|_| ());
        // errors if the receiver side is gone which is OK.
        sender.send(waitpid_res).ok();
    });
    match receiver.recv_timeout(timeout) {
        Ok(Ok(())) => Ok(()),
        Ok(Err(e)) => {
            info!("Cannot wait for child: {e}");
            Err(())
        }
        Err(_) => {
            info!("Timeout waiting for child");
            Err(())
        }
    }
}
fn wait_timeout ( pid : nix :: unistd :: Pid , timeout : Duration ) -> Result < ( ) , ( ) > { use nix :: sys :: wait :: waitpid ; // use some thread and channel trickery, see https://stackoverflow.com/a/42720480 let ( sender , receiver ) = std :: sync :: mpsc :: channel ( ) ; std :: thread :: spawn ( move | | { let waitpid_res = waitpid ( pid , None ) . map ( | _ | ( ) ) ; // errors if the receiver side is gone which is OK. sender . send ( waitpid_res ) . ok ( ) ; } ) ; match receiver . recv_timeout ( timeout ) { Ok ( Ok ( ( ) ) ) => Ok ( ( ) ) , Ok ( Err ( e ) ) => { info ! ( " " ) ; Err ( ( ) ) } Err ( _ ) => { info ! ( " " ) ; Err ( ( ) ) } } }
Wait for given PID to exit with a timeout.
Wait for given PID to exit with a timeout .
pid
nix::unistd::Pid
timeout
Duration