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
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
open
the PID as soon as possible, before any potentialwait
operations, to mitigate the issue. - 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.
sourcepub fn wait(&mut self) -> Result<()>
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.
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, 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.