pub struct Process { /* private fields */ }Expand description
A handle to a spawned process.
§Fork Safety
The process handle contains a PID. After a fork, the child process will
have a copy of this PID, but it refers to the same original process.
Calling wait or kill from the child may lead to confusing results
if multiple processes are managing the same PID.
When the process was spawned by SpawnBackend::Clone3Pidfd, the handle
additionally owns the child’s pidfd. Signaling then uses
pidfd_send_signal, which cannot race with pid reuse, and exit detection
polls the pidfd. The pidfd is closed when the handle is dropped.
Implementations§
Source§impl Process
impl Process
Sourcepub fn wait_step(&self) -> Result<Option<ExitStatus>, CoreError>
pub fn wait_step(&self) -> Result<Option<ExitStatus>, CoreError>
Perform a non-blocking wait for process termination.
When the handle owns a pidfd, the wait first polls the pidfd (which
becomes readable exactly when the child exits) and then reaps with
waitpid, avoiding the ECHILD-race of polling waitpid directly.
§Errors
ECHILD: The process does not exist or is not a child of the caller.EINTR: The call was interrupted by a signal (handled internally).
Sourcepub fn wait_blocking(&self) -> Result<ExitStatus, CoreError>
pub fn wait_blocking(&self) -> Result<ExitStatus, CoreError>
Block until the process terminates.
§Errors
ECHILD: The process does not exist or is not a child of the caller.
Sourcepub fn kill(&self, sig: i32) -> Result<(), CoreError>
pub fn kill(&self, sig: i32) -> Result<(), CoreError>
Send a signal to the process.
When the handle owns a pidfd, the signal is delivered with
pidfd_send_signal, which cannot target a recycled pid; on kernels
without it (ENOSYS, kernel < 5.1) it falls back to kill.
§Errors
EINVAL: Invalid signal number, or a non-positive pid (pid0would signal the caller’s own process group).EPERM: The caller does not have permission to send the signal.ESRCH: The process does not exist.
Sourcepub fn kill_pgroup(&self, sig: i32) -> Result<(), CoreError>
pub fn kill_pgroup(&self, sig: i32) -> Result<(), CoreError>
Signal the process group whose id equals Self::pid — valid only
when the process is its own group/session leader. For a child placed
into a custom leader’s group use Self::kill_group.
§Errors
Same as Self::kill.
Sourcepub fn kill_group(&self, pgid: pid_t, sig: i32) -> Result<(), CoreError>
pub fn kill_group(&self, pgid: pid_t, sig: i32) -> Result<(), CoreError>
Send a signal to an explicit process group.
The pgid must be the child’s actual group (its own pid after setsid,
or the configured leader’s id after setpgid), never guessed from the
pid, and never 0 or negative — kill(-0) would signal the caller’s
own process group.
§Errors
Same as Self::kill, plus EINVAL for a non-positive pgid.