Struct PidFd

struct PidFd { ... }

This type represents a file descriptor that refers to a process.

A PidFd can be obtained by setting the corresponding option on Command with create_pidfd. Subsequently, the created pidfd can be retrieved from the Child by calling pidfd or into_pidfd.

Example:

#![feature(linux_pidfd)]
use std::os::linux::process::{CommandExt, ChildExt};
use std::process::Command;

let mut child = Command::new("echo")
    .create_pidfd(true)
    .spawn()
    .expect("Failed to spawn child");

let pidfd = child
    .into_pidfd()
    .expect("Failed to retrieve pidfd");

// The file descriptor will be closed when `pidfd` is dropped.

Refer to the man page of pidfd_open(2) for further details.

Implementations

impl PidFd

fn kill(self: &Self) -> Result<()>

Forces the child process to exit.

Unlike Child::kill it is possible to attempt to kill reaped children since PidFd does not suffer from pid recycling races. But doing so will return an Error.

fn wait(self: &Self) -> Result<ExitStatus>

Waits for the child to exit completely, returning the status that it exited with.

Unlike Child::wait it does not ensure that the stdin handle is closed.

Additionally on kernels prior to 6.15 only the first attempt to reap a child will return an ExitStatus, further attempts will return an Error.

fn try_wait(self: &Self) -> Result<Option<ExitStatus>>

Attempts to collect the exit status of the child if it has already exited.

On kernels prior to 6.15, and unlike Child::try_wait, only the first attempt to reap a child will return an ExitStatus, further attempts will return an Error.

impl AsFd for PidFd

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

impl AsRawFd for PidFd

fn as_raw_fd(self: &Self) -> RawFd

impl Debug for PidFd

fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result

impl Freeze for PidFd

impl From for PidFd

fn from(fd: OwnedFd) -> Self

impl FromRawFd for PidFd

unsafe fn from_raw_fd(fd: RawFd) -> Self

impl IntoRawFd for PidFd

fn into_raw_fd(self: Self) -> RawFd

impl RefUnwindSafe for PidFd

impl Send for PidFd

impl Sync for PidFd

impl Unpin for PidFd

impl UnwindSafe for PidFd

impl<T> Any for PidFd

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for PidFd

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for PidFd

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

impl<T> From for PidFd

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for PidFd

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for PidFd

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

impl<T, U> TryInto for PidFd

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