Skip to main content

Child

Struct Child 

Source
pub struct Child { /* private fields */ }
Available on crate feature 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

Source

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.

Source

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.

Source

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.

Source

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.

Source§

fn as_handle(&self) -> BorrowedHandle<'_>

Borrows the handle. Read more
Source§

impl Debug for Child

Shows the child’s identity — pid, drop policy, and any cached exit status — rather than the raw process and job handles, whose values are noise that varies between runs.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Child

§

impl RefUnwindSafe for Child

§

impl Send for Child

§

impl Sync for Child

§

impl Unpin for Child

§

impl UnsafeUnpin for Child

§

impl UnwindSafe for Child

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more