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
impl ChildLock
Sourcepub fn new(child: Child) -> Self
pub fn new(child: Child) -> Self
Wraps a Child in a LockWithTimeout, allowing timed read/write locks on the
child handle.
Sourcepub fn update(self, new_child: Child) -> Self
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.
Sourcepub fn clone(&self) -> Self
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.
Sourcepub async fn kill(&self) -> Result<(), ErrorArrayItem>
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
ErrorArrayItemon I/O issues or if reaping fails. - If the child’s PID is invalid, returns an error.
Sourcepub async fn try_wait(&self) -> Result<Option<ExitStatus>, ErrorArrayItem>
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
ErrorArrayItemif the child lock can’t be acquired in time.
Sourcepub async fn running(&self) -> bool
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§
impl !RefUnwindSafe for ChildLock
impl !UnwindSafe for ChildLock
impl Freeze for ChildLock
impl Send for ChildLock
impl Sync for ChildLock
impl Unpin for ChildLock
impl UnsafeUnpin for ChildLock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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