pub struct ProcessHandle { /* private fields */ }Expand description
An independent exit reader. On Unix it shares the owner’s cached reap state; on Windows it owns a duplicated process handle, never a borrowed handle value. Keeping this reader alive does not keep an owned process tree alive.
Unix: wait, try_wait and wait_timeout reap the leader when it has exited. The first
reap by any path, this reader or the owner, permanently ends process-group signalling for
the OwnedChild and every clone: the group id may be recycled from then on, so nothing is
sent to it again. A reader that reaps therefore also means the owner can no longer kill
descendants that outlive the leader.
wait_exited is the monitor’s call: it returns once the leader has
exited without reaping it, so the owner can still terminate the group (the leader’s
zombie pins the group id) and then reap. A monitor thread that only needs to learn of the
exit, to wake a run loop for instance, should use it, and leave the reap to the owner.
Implementations§
Source§impl ProcessHandle
impl ProcessHandle
pub fn try_clone(&self) -> Result<Self>
Sourcepub fn creation_time(&self) -> Option<SystemTime>
pub fn creation_time(&self) -> Option<SystemTime>
Native creation time on Windows/macOS; spawn observation time on other Unix hosts.
pub fn try_wait(&self) -> Result<Option<ExitStatus>>
Sourcepub fn wait(&self) -> Result<ExitStatus>
pub fn wait(&self) -> Result<ExitStatus>
Blocks until the leader exits and reaps it (Unix) or until the process exits (Windows).
Unix: a loop of non-blocking try_wait looks. Each look takes the shared lock and
releases it at once; between looks the thread sleeps, ending early at the child’s exit
where the kernel offers an event (a hint, see exit_watch) and otherwise after 5 ms. The
lock is never held while this thread sleeps, so kill, terminate_tree and other
waiters run meanwhile (unless some other thread holds an OwnedChild::child() guard,
which is the lock itself), and no wait system call names the pid outside the lock: a
blocked waitid(pid) entered after another reader reaped the leader and the kernel
recycled the number would wait on an unrelated child.
Sourcepub fn wait_exited(&self) -> Result<()>
pub fn wait_exited(&self) -> Result<()>
Blocks until the leader has exited, and does not reap it.
Unix: returns when the leader is a zombie (or was already reaped by someone). The zombie
still pins the pid and the process-group id, so the owner can keep signalling the group
(OwnedChild::wait_or_kill, terminate_tree*) and then reap. This is the call for an
exit monitor that must not end the owner’s ability to kill descendants that outlive the
leader; wait and try_wait reap and do end it. Waits like wait, with
the non-reaping waitid(WNOHANG | WNOWAIT) probe as its look. Hosts with no verified
non-reaping probe (Unix other than Linux, Android, macOS and iOS) have nothing to
observe with, so there this reaps exactly like wait.
Windows: returns once the process has exited; nothing is reaped there.
Sourcepub fn wait_exited_timeout(&self, timeout: Duration) -> Result<bool>
pub fn wait_exited_timeout(&self, timeout: Duration) -> Result<bool>
wait_exited with a limit: true once the leader has exited
(without reaping it on Linux, Android, macOS and iOS), false if timeout passed first.
For a caller that must enforce a deadline and still keep the group killable while it
drains the leader’s pipes; it reaps afterwards with wait. Hosts with no non-reaping
probe behave like wait_timeout.