pub struct PidFd { /* private fields */ }Expand description
A file descriptor that refers to a process.
This type represents a Linux pidfd (process file descriptor), which is a file descriptor that refers to a process. Unlike traditional PIDs, pidfds cannot be reused, making them safe from PID reuse race conditions.
On nightly Rust with the nightly feature, this re-exports std::os::linux::process::PidFd.
On stable Rust, this provides a compatible implementation.
Implementations§
Source§impl PidFd
impl PidFd
Sourcepub fn kill(&self) -> Result<()>
pub fn kill(&self) -> Result<()>
Sends SIGKILL to the process referred to by the pidfd.
This is a convenience method equivalent to send_signal(libc::SIGKILL).
Sourcepub fn wait(&self) -> Result<ExitStatus>
pub fn wait(&self) -> Result<ExitStatus>
Waits for the process referred to by the pidfd to exit and returns its exit status.
This method blocks until the process exits. Use try_wait
for a non-blocking alternative, or AsyncPidFd::wait
for async code.
Sourcepub fn try_wait(&self) -> Result<Option<ExitStatus>>
pub fn try_wait(&self) -> Result<Option<ExitStatus>>
Checks if the process referred to by the pidfd has exited without blocking.
Returns Ok(Some(status)) if the process has exited, Ok(None) if it’s still running.
Trait Implementations§
Source§impl AsFd for PidFd
impl AsFd for PidFd
Source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Source§impl FromRawFd for PidFd
impl FromRawFd for PidFd
Source§unsafe fn from_raw_fd(fd: RawFd) -> Self
unsafe fn from_raw_fd(fd: RawFd) -> Self
Self from the given raw file
descriptor. Read moreSource§impl IntoRawFd for PidFd
impl IntoRawFd for PidFd
Source§fn into_raw_fd(self) -> RawFd
fn into_raw_fd(self) -> RawFd
Source§impl PidFdExt for PidFd
impl PidFdExt for PidFd
Source§fn from_pid(pid: i32) -> Result<PidFd>
fn from_pid(pid: i32) -> Result<PidFd>
PidFd from a process ID. Calling this is highly discouraged as it is racy and
the resulting pidfd might not refer to the expected process. Read moreSource§fn get_ppid(&self) -> Result<i32>
fn get_ppid(&self) -> Result<i32>
Source§fn get_id(&self) -> Result<u64>
fn get_id(&self) -> Result<u64>
Source§fn get_creds(&self) -> Result<PidFdCreds>
fn get_creds(&self) -> Result<PidFdCreds>
Source§fn get_namespace(&self, ns: &PidFdGetNamespace) -> Result<OwnedFd>
fn get_namespace(&self, ns: &PidFdGetNamespace) -> Result<OwnedFd>
ns of the process referred to by the pidfd. Read moreSource§fn access_proc<R, F: FnOnce() -> R>(&self, func: F) -> Result<R>
fn access_proc<R, F: FnOnce() -> R>(&self, func: F) -> Result<R>
Source§fn send_signal(&self, signal: i32) -> Result<()>
fn send_signal(&self, signal: i32) -> Result<()>
libc::SIGTERM) to the process referred to by the pidfd. Read more