pub struct ChildManager {
children: Vec<Child>,
shut_down: bool,
}Expand description
Manages child processes spawned by snarkos commands, ensuring they can be gracefully terminated and reaped.
- On Unix, we rely on
setsid()at spawn + sending signals to the process group viakill(-pid, SIGTERM|SIGKILL)so helpers die too. - On Windows, we rely on a Job Object (created/managed elsewhere) to ensure the tree is contained and hard-killed as a backstop; we still explicitly terminate lingering children during shutdown.
Fields§
§children: Vec<Child>All direct snarkos children.
Invariant: a Child is inserted exactly once and removed never.
shut_down: boolEnsures shutdown is idempotent even if called multiple times (explicit + Drop).
Implementations§
Source§impl ChildManager
impl ChildManager
Sourcepub fn push(&mut self, child: Child)
pub fn push(&mut self, child: Child)
Register a freshly–spawned child so it can be reaped later.
Sourcepub fn shutdown_all(&mut self, timeout: Duration)
pub fn shutdown_all(&mut self, timeout: Duration)
Graceful-then-forceful termination sequence (idempotent):
- Polite: ask everyone to exit.
- Unix: send
SIGTERMto the process group of each child viakill(-pid, SIGTERM). - Windows: no-op by default — rely on app-level handling and Job Objects.
- Unix: send
- Wait up to
timeoutfor children to exit (pollingtry_wait). - Hard kill survivors:
- Unix:
kill(-pid, SIGKILL). - Windows:
Child::kill()(TerminateProcess). Job Object is a safety net.
- Unix:
- Reap: call
wait()on all children to avoid zombies (ignore errors).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ChildManager
impl RefUnwindSafe for ChildManager
impl Send for ChildManager
impl Sync for ChildManager
impl Unpin for ChildManager
impl UnwindSafe for ChildManager
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
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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 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>
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