pub struct Child { /* private fields */ }blocking only.Expand description
A running (or finished) root child of a pseudoconsole session.
The handle owns the session’s job object as well as the process handle, so
Child::kill terminates the whole process tree rather than just the
process this crate created.
Every publicly obtainable Child is managed and kill-on-drop. Dropping it
does not wait; the Job terminates the root process and every descendant
still running.
The process handle is available only through the lifetime-safe
AsHandle implementation; a hidden compile-fail doctest pins the
missing raw-handle escape hatch.
Implementations§
Source§impl Child
impl Child
Sourcepub const fn id(&self) -> u32
pub const fn id(&self) -> u32
Returns the child’s process identifier.
The identifier stays valid as long as this Child is alive; once the
process handle is closed, Windows may reuse the number.
Sourcepub fn wait(&mut self) -> Result<ExitStatus>
pub fn wait(&mut self) -> Result<ExitStatus>
Waits for the child to exit and returns its status.
Repeated calls return the cached status instead of waiting again.
§Deadlock
The child must be able to make progress while this blocks, which means something else has to drain the session’s output — see the module docs.
§Errors
An error with crate::ErrorKind::Wait wrapping the OS error from
WaitForSingleObject or GetExitCodeProcess.
Sourcepub fn try_wait(&mut self) -> Result<Option<ExitStatus>>
pub fn try_wait(&mut self) -> Result<Option<ExitStatus>>
Returns the exit status if the child has already exited, without blocking.
§Errors
An error with crate::ErrorKind::Wait wrapping the OS error from
WaitForSingleObject or GetExitCodeProcess.
Sourcepub fn kill(&mut self) -> Result<()>
pub fn kill(&mut self) -> Result<()>
Terminates the child and every descendant it created.
This terminates the session’s job object, so processes the child
spawned are killed too. Termination is asynchronous: call
Child::wait afterwards to observe the resulting status, which is
exit code 1.
Killing an already-finished tree succeeds and does nothing.
§Errors
An error with crate::ErrorKind::Kill wrapping the OS error from
TerminateJobObject.
Trait Implementations§
Source§impl AsHandle for Child
Borrows the child’s process handle, e.g. to duplicate it or to wait on it
together with other objects.
impl AsHandle for Child
Borrows the child’s process handle, e.g. to duplicate it or to wait on it together with other objects.