Skip to main content

ProcessHandle

Struct ProcessHandle 

Source
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

Source

pub fn try_clone(&self) -> Result<Self>

Source

pub fn creation_time(&self) -> Option<SystemTime>

Native creation time on Windows/macOS; spawn observation time on other Unix hosts.

Source

pub fn try_wait(&self) -> Result<Option<ExitStatus>>

Source

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.

Source

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.

Source

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.

Source

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

Trait Implementations§

Source§

impl Debug for ProcessHandle

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.