pub struct Process(/* private fields */);Expand description
A handle to a running or finished subprocess.
Process is a lightweight handle that tracks a child process’s lifecycle. It is
created internally by Exec::start and Pipeline::start and appears as part of
the Job struct.
Unlike std::process::Child, all methods on Process take &self rather than &mut self, so a Process can be shared between threads without external synchronization.
Process is cheaply cloneable. Clones share the same underlying process handle, so
e.g. calling wait() on one clone will also make the exit status available to all
other clones.
§Drop behavior
When the last clone of a Process is dropped, it waits for the child process to
finish unless detach has been called. Because Process does not own
any pipes to the child, callers must ensure that any pipes connected to the child’s
stdin are dropped before the Process is dropped. Otherwise, the child may block
waiting for input while the Process drop waits for the child to exit, resulting in a
deadlock. Job handles this automatically via field declaration order.
Implementations§
Source§impl Process
impl Process
Sourcepub fn exit_status(&self) -> Option<ExitStatus>
pub fn exit_status(&self) -> Option<ExitStatus>
Sourcepub fn poll(&self) -> Option<ExitStatus>
pub fn poll(&self) -> Option<ExitStatus>
Check whether the process has finished, without blocking.
Returns Some(exit_status) if the process has finished, None if it is still
running.
Sourcepub fn wait(&self) -> Result<ExitStatus>
pub fn wait(&self) -> Result<ExitStatus>
Wait for the process to finish and return its exit status.
If the process has already finished, returns the cached exit status immediately.
Sourcepub fn wait_timeout(&self, dur: Duration) -> Result<Option<ExitStatus>>
pub fn wait_timeout(&self, dur: Duration) -> Result<Option<ExitStatus>>
Wait for the process to finish, timing out after the specified duration.
Returns Ok(None) if the timeout elapsed before the process finished.
Sourcepub fn terminate(&self) -> Result<()>
pub fn terminate(&self) -> Result<()>
Terminate the subprocess.
On Unix, this sends SIGTERM. On Windows, this calls TerminateProcess.
If the process has already been reaped, this is a no-op to avoid signaling a potentially reused PID.