Skip to main content

ChildLock

Struct ChildLock 

Source
pub struct ChildLock(pub LockWithTimeout<Child>);
Expand description

A wrapper around LockWithTimeout<Child> that synchronizes access to a tokio::process::Child. This allows safe concurrent reads/writes or attempts to kill the child within specified timeouts.

Tuple Fields§

§0: LockWithTimeout<Child>

Implementations§

Source§

impl ChildLock

Source

pub fn new(child: Child) -> Self

Wraps a Child in a LockWithTimeout, allowing timed read/write locks on the child handle.

Source

pub fn update(self, new_child: Child) -> Self

Replaces the child handle within this lock. Typically used when restarting or re-spawning the same command.

Source

pub fn clone(&self) -> Self

Clones the internal lock (i.e., Arc-based duplication). This does not duplicate the child process, only the lock mechanism that references it.

Source

pub async fn kill(&self) -> Result<(), ErrorArrayItem>

Recursively terminates the child’s process group. Sends SIGTERM to all descendant PIDs and then SIGKILL to any that remain, logging progress at Trace level.

§Errors
  • Returns an ErrorArrayItem on I/O issues or if reaping fails.
  • If the child’s PID is invalid, returns an error.
Source

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

Non-blocking check for whether the child has already exited.

This calls tokio::process::Child::try_wait under the hood, which performs a waitpid(..., WNOHANG) on our behalf. Unlike a raw kill(pid, 0) signal check, this correctly reports an exited process as no longer running (rather than as a still-existing zombie), and it reaps the process in the same call so it never lingers as a zombie.

§Returns
  • Ok(Some(status)) if the process has already exited (now reaped).
  • Ok(None) if the process is still running.
§Errors
  • Returns an ErrorArrayItem if the child lock can’t be acquired in time.
Source

pub async fn running(&self) -> bool

Checks if the child is still running – the one true liveness check for a process we hold a real tokio::process::Child handle for.

This reaps via try_wait rather than signaling the PID directly, so an exited-but-unreaped child (a zombie) is correctly reported as not running instead of appearing alive.

A lock-acquisition timeout is treated as “unknown” and reported as still running, so callers don’t tear down a healthy child on transient contention. Any other error (e.g. the OS reporting no such child, which happens if the process was already reaped elsewhere, such as by a concurrent kill()) is treated as “not running”.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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