pub async fn pid_wait(pid: Pid) -> ProcessResult<()> {
    // `waitpid` might block indefinitely,
    // we need to handle that
    let waited = rt::spawn_blocking(move || {
        let result = unsafe { libc::waitpid(pid, ptr::null_mut(), 0) };
        if result == -1 {
            // Do not care about the error type at this point
            Err(())
        } else {
            Ok(())
        }
    })
    .await;

    // Task finished correctly and `waitpid` succeeded too
    if waited.is_ok() {
        return Ok(());
    }
    // If either task failed or `waitpid` failed,
    // it could mean that either `pid` is not our child
    // or there is no such a process at all.
    // Same to `psutil`, there is nothing left to do,
    // except for a naive checking for pid existence in a loop

    let interval = rt::time::interval(Duration::from_millis(40));
    futures::pin_mut!(interval);
    while let Some(..) = interval.next().await {
        if !pid_exists(pid) {
            return Ok(());
        }
    }

    // Logically speaking, this branch is unreachable, as `time::interval`
    // is infinite, but in order to make compiler happy,
    // let's show some error
    let e = Error::from(io::Error::from(io::ErrorKind::Other))
        .with_message("Unable to await for process termination");
    Err(e.into())
}
/// Wait for the process termination.
Wait for the process termination.
Wait for the process termination .
pub async fn pid_wait(pid: Pid) -> ProcessResult<()> {
    // `waitpid` might block indefinitely,
    // we need to handle that
    let waited = rt::spawn_blocking(move || {
        let result = unsafe { libc::waitpid(pid, ptr::null_mut(), 0) };
        if result == -1 {
            // Do not care about the error type at this point
            Err(())
        } else {
            Ok(())
        }
    })
    .await;
    // Task finished correctly and `waitpid` succeeded too
    if waited.is_ok() {
        return Ok(());
    }
    // If either task failed or `waitpid` failed,
    // it could mean that either `pid` is not our child
    // or there is no such a process at all.
    // Same to `psutil`, there is nothing left to do,
    // except for a naive checking for pid existence in a loop
    let interval = rt::time::interval(Duration::from_millis(40));
    futures::pin_mut!(interval);
    while let Some(..) = interval.next().await {
        if !pid_exists(pid) {
            return Ok(());
        }
    }
    // Logically speaking, this branch is unreachable, as `time::interval`
    // is infinite, but in order to make compiler happy,
    // let's show some error
    let e = Error::from(io::Error::from(io::ErrorKind::Other))
        .with_message("Unable to await for process termination");
    Err(e.into())
}
pub async fn pid_wait ( pid : Pid ) -> ProcessResult < ( ) > { // `waitpid` might block indefinitely, // we need to handle that let waited = rt :: spawn_blocking ( move | | { let result = unsafe { libc :: waitpid ( pid , ptr :: null_mut ( ) , 0 ) } ; if result == - 1 { // Do not care about the error type at this point Err ( ( ) ) } else { Ok ( ( ) ) } } ) . await ; // Task finished correctly and `waitpid` succeeded too if waited . is_ok ( ) { return Ok ( ( ) ) ; } // If either task failed or `waitpid` failed, // it could mean that either `pid` is not our child // or there is no such a process at all. // Same to `psutil`, there is nothing left to do, // except for a naive checking for pid existence in a loop let interval = rt :: time :: interval ( Duration :: from_millis ( 40 ) ) ; futures :: pin_mut ! ( interval ) ; while let Some ( .. ) = interval . next ( ) . await { if ! pid_exists ( pid ) { return Ok ( ( ) ) ; } } // Logically speaking, this branch is unreachable, as `time::interval` // is infinite, but in order to make compiler happy, // let's show some error let e = Error :: from ( io :: Error :: from ( io :: ErrorKind :: Other ) ) . with_message ( " " ) ; Err ( e . into ( ) ) }
Wait for the process termination.
Wait for the process termination .
pid
Pid
pid
Pid