Struct waitpid_any::WaitHandle

source ·
pub struct WaitHandle(/* private fields */);
Expand description

A locked handle to a process.

See WaitHandle::open for more details.

Implementations§

source§

impl WaitHandle

source

pub fn open(pid: i32) -> Result<Self>

Open an handle to the process with given PID.

The opened handle always points to the same process entity, thus preventing race condition caused by PID reusing.

Errors

Fails when the underlying syscall fails.

Caveats
  1. PID itself does not own any resource in most platforms. Thus there is still a race condition when the process pointed by the original PID is dead, reaped, and recycled all before calling to this function. This is generally unavoidable. But you can try to open the PID as soon as possible, before any potential wait operations, to mitigate the issue.
  2. If the given PID does not exists, it returns ESRCH on *NIX immediately. This can also happen if the process is exited and reaped before this call. You may want to regards this case as a successful wait, but the decision is up to you.
source

pub fn wait(&mut self) -> Result<()>

Blocks until the target process exits.

Once the the target process exits, all following calls return Ok(()) immediately.

Errors

Fails when the underlying syscall fails. For *NIX platforms, EINTR may be returned in case of signals.

source

pub fn wait_timeout(&mut self, timeout: Duration) -> Result<Option<()>>

Blocks until the target process exits, or timeout.

If the process exited in time, Ok(Some(())) is returned immediately when the event triggers. If it is not exited in timeout, Ok(None) is returned. Once the the target process exits, all following calls return Ok(Some(())) immediately.

Errors

Fails when the underlying syscall fails. For *NIX platforms, EINTR may be returned in case of signals.

Trait Implementations§

source§

impl Debug for WaitHandle

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.