pub struct UnixProcess { /* private fields */ }Expand description
A spawned Unix process and its supporting tasks.
The exit watcher owns the child, records its exit code in ExitCodeCell, and cancels the provided exit token.
Background log pumps forward stdout/stderr lines to a shared sink.
The child leads a new process group so signals reach it and descendants that remain in the group.
Call cleanup to give the group time to shut down gracefully before sending SIGKILL.
Dropping the value also sends SIGKILL unless cleanup has already sent it.
§Limits
- Descendants can escape group signals by changing groups (for example with
setsid). If they hold stdout or stderr open,cleanupaborts the log pumps after a timeout. Dropdoes not run if the owning process is killed by SIGKILL or the OOM killer, or callsstd::process::exit.- The OS may reuse an empty group’s ID before
killpgruns, risking a signal to an unrelated group.
Implementations§
Source§impl UnixProcess
impl UnixProcess
Sourcepub async fn spawn(
config: UnixProcessConfig,
log_sink: Arc<Mutex<dyn LogSink>>,
exit_token: CancellationToken,
) -> Result<Self, GenericError>
pub async fn spawn( config: UnixProcessConfig, log_sink: Arc<Mutex<dyn LogSink>>, exit_token: CancellationToken, ) -> Result<Self, GenericError>
Spawns the process described by config. The provided log_sink receives each line of
captured stdout/stderr; the provided exit_token is cancelled when the process exits.
Sourcepub fn exit_code_cell(&self) -> ExitCodeCell
pub fn exit_code_cell(&self) -> ExitCodeCell
Returns a clone of the shared ExitCodeCell.
Wait for the exit token passed to spawn before reading.
Sourcepub async fn cleanup(self)
pub async fn cleanup(self)
Stops the process group and waits for its background tasks.
Sends SIGTERM to the group, allows a grace period for shutdown, then sends SIGKILL. Waits for the exit watcher and log pumps to finish, aborting unfinished tasks after a timeout.
Dropping this future before SIGKILL drops the UnixProcess, which sends SIGKILL instead.