Struct waitpid_any::WaitHandle
source · pub struct WaitHandle(_);Expand description
A locked handle to a process.
See WaitHandle::open for more details.
Implementations§
source§impl WaitHandle
impl WaitHandle
sourcepub fn open(pid: i32) -> Result<Self>
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
- 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
openthe PID as soon as possible, before any potentialwaitoperations, to mitigate the issue. - If the given PID does not exists, it returns
ESRCHon *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.
sourcepub fn wait(&mut self) -> Result<()>
pub fn wait(&mut self) -> Result<()>
Blocks until the target process exits, and then returns Ok(()).
Errors
Fails when the underlying syscall fails.
sourcepub fn wait_timeout(&mut self, timeout: Duration) -> Result<Option<()>>
pub fn wait_timeout(&mut self, timeout: Duration) -> Result<Option<()>>
Blocks until the target process exits, and then returns Ok(Some(())).
If the process is not exited in timeout, it returns None.
Errors
Fails when the underlying syscall fails, or the process is still not exited after
timeout elapsed.
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for WaitHandle
impl Send for WaitHandle
impl Sync for WaitHandle
impl Unpin for WaitHandle
impl UnwindSafe for WaitHandle
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more