Skip to main content

PidFd

Struct PidFd 

Source
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

Source

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).

Source

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.

Source

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

Source§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
Source§

impl AsRawFd for PidFd

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl From<OwnedFd> for PidFd

Source§

fn from(fd: OwnedFd) -> Self

Converts to this type from the input type.
Source§

impl From<PidFd> for OwnedFd

Source§

fn from(pid_fd: PidFd) -> Self

Converts to this type from the input type.
Source§

impl FromRawFd for PidFd

Source§

unsafe fn from_raw_fd(fd: RawFd) -> Self

Constructs a new instance of Self from the given raw file descriptor. Read more
Source§

impl IntoRawFd for PidFd

Source§

fn into_raw_fd(self) -> RawFd

Consumes this object, returning the raw underlying file descriptor. Read more
Source§

impl PidFdExt for PidFd

Source§

fn from_self() -> Result<PidFd>

Creates a PidFd for the current process.
Source§

fn from_pid(pid: i32) -> Result<PidFd>

Creates a 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 more
Source§

fn get_pid(&self) -> Result<i32>

Gets the process ID of the process referred to by the pidfd.
Source§

fn get_ppid(&self) -> Result<i32>

Gets the process ID of the parent process referred to by the pidfd.
Source§

fn get_id(&self) -> Result<u64>

Gets a unique identifier of the process referred to by the pidfd. Read more
Source§

fn get_creds(&self) -> Result<PidFdCreds>

Gets the credentials (UIDs and GIDs) of the process referred to by the pidfd. Read more
Source§

fn get_cgroupid(&self) -> Result<u64>

Gets the cgroup ID of the process. Read more
Source§

fn get_namespace(&self, ns: &PidFdGetNamespace) -> Result<OwnedFd>

Gets a file descriptor to a namespace of type ns of the process referred to by the pidfd. Read more
Source§

fn access_proc<R, F: FnOnce() -> R>(&self, func: F) -> Result<R>

Executes a function with protection against PID reuse. Read more
Source§

fn send_signal(&self, signal: i32) -> Result<()>

Sends a signal (e.g., libc::SIGTERM) to the process referred to by the pidfd. Read more
Source§

fn set_namespace(&self, ns: CloneFlags) -> Result<()>

Moves the calling process into the namespaces of the process referred to by the pidfd. Read more
Source§

fn get_remote_fd(&self, target_fd: i32) -> Result<OwnedFd>

Installs a duplicate of a file descriptor from the process referred to by the pidfd in the current process. Read more
Source§

impl TryFrom<PidFd> for AsyncPidFd

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(pifd: PidFd) -> Result<Self, Error>

Performs the conversion.

Auto Trait Implementations§

§

impl !Freeze for PidFd

§

impl !RefUnwindSafe for PidFd

§

impl Send for PidFd

§

impl !Sync for PidFd

§

impl Unpin for PidFd

§

impl UnsafeUnpin for PidFd

§

impl !UnwindSafe for PidFd

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsSource for T
where T: AsFd,

Source§

fn source(&self) -> BorrowedFd<'_>

Returns the borrowed file descriptor.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.