pub struct Process { /* private fields */ }Expand description
A handle to a process this VFS did not spawn.
Holding one is what makes the operations below refer to a single process rather than to whatever currently owns a PID. How strong that guarantee is varies:
- Linux (
pidfd) and Windows (a process handle pins the PID against reuse) are race-free for the whole life of the handle. - FreeBSD and macOS validate identity at open and cannot maintain it:
kill(2)takes a PID, and Capsicum mints process descriptors only throughpdfork, so there is no handle to hold for a process this one did not fork.Process::signalandProcess::terminateare racy there.
Implementations§
Source§impl Process
impl Process
Sourcepub fn pid(&self) -> u32
pub fn pid(&self) -> u32
Returns the process ID.
The only attribute projected directly: it is fixed for the life of the handle, where everything else has to be re-read to be true.
Sourcepub async fn info(&self) -> Result<ProcessInfo>
pub async fn info(&self) -> Result<ProcessInfo>
Takes a fresh snapshot of the process.
Sourcepub async fn signal(&self, signal: Signal) -> Result<()>
pub async fn signal(&self, signal: Signal) -> Result<()>
Sends a signal to the process.
Fails with ErrorKind::Unsupported
on a Windows target. The method exists there regardless, because the
target may be remote: whether signals exist is a property of the target,
not of the host this code was compiled for.
Sourcepub async fn terminate(&self) -> Result<()>
pub async fn terminate(&self) -> Result<()>
Asks the process to terminate.
SIGTERM on Unix, TerminateProcess on Windows. Unconditional, with no
grace period and no escalation, unlike
Child::terminate: the graceful half of that
path relies on children being spawned into a process group of their own,
which is not something that can be arranged after the fact. Compose
terminate, wait, a timeout, and kill
for grace with escalation.
Note the asymmetry this leaves on Windows, where TerminateProcess is
not a request the target can decline or clean up after.
Sourcepub async fn kill(&self) -> Result<()>
pub async fn kill(&self) -> Result<()>
Kills the process.
SIGKILL on Unix, TerminateProcess on Windows — the strongest stop
the target offers, and one the process cannot catch or clean up after.
On a Windows target this is terminate under another
name, since TerminateProcess is already unconditional and there is
nothing harder to escalate to. The pair exists because on Unix the
distinction is real, and a portable caller should be able to ask for
either without branching on the target.
Sourcepub async fn wait(&self) -> Result<ProcessExit>
pub async fn wait(&self) -> Result<ProcessExit>
Waits for the process to exit.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Process
impl !UnwindSafe for Process
impl Freeze for Process
impl Send for Process
impl Sync for Process
impl Unpin for Process
impl UnsafeUnpin for Process
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
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