pub struct Pid(/* private fields */);
process
only.Expand description
pid_t
—A non-zero Unix process ID.
This is a pid, and not a pidfd. It is not a file descriptor, and the process it refers to could disappear at any time and be replaced by another, unrelated, process.
On Linux, Pid
values are also used to identify threads.
Implementations§
Source§impl Pid
impl Pid
Sourcepub const fn from_raw(raw: RawPid) -> Option<Self>
pub const fn from_raw(raw: RawPid) -> Option<Self>
Converts a RawPid
into a Pid
.
Returns Some
for positive values, and None
for zero values.
This is safe because a Pid
is a number without any guarantees for the
kernel. Non-child Pid
s are always racy for any syscalls, but can only
cause logic errors. If you want race-free access to or control of
non-child processes, please consider other mechanisms like pidfd on
Linux.
Passing a negative number doesn’t invoke undefined behavior, but it may cause unexpected behavior.
Sourcepub const unsafe fn from_raw_unchecked(raw: RawPid) -> Self
pub const unsafe fn from_raw_unchecked(raw: RawPid) -> Self
Converts a known positive RawPid
into a Pid
.
Passing a negative number doesn’t invoke undefined behavior, but it may cause unexpected behavior.
§Safety
The caller must guarantee raw
is non-zero.
Sourcepub fn from_child(child: &Child) -> Self
pub fn from_child(child: &Child) -> Self
Creates a Pid
holding the ID of the given child process.
Sourcepub const fn as_raw_nonzero(self) -> NonZeroI32
pub const fn as_raw_nonzero(self) -> NonZeroI32
Converts a Pid
into a NonZeroI32
.