Struct PidFd
#[repr(transparent)]
pub struct PidFd { pub(in ::os::linux::process) inner: InnerPidFd }
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.
Examples
#![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.
Fields
inner: InnerPidFd
Implementations
impl PidFd
fn kill(&self) -> Result<()>Forces the child process to exit.
Unlike
Child::killit 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) -> Result<ExitStatus>Waits for the child to exit completely, returning the status that it exited with.
Unlike
Child::waitit 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) -> 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.
Trait Implementations
impl AsFd for PidFd
fn as_fd(&self) -> BorrowedFd<'_>
impl AsInner<InnerPidFd> for PidFd
fn as_inner(&self) -> &InnerPidFd
impl AsRawFd for PidFd
fn as_raw_fd(&self) -> RawFd
impl Debug for PidFd
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl From<OwnedFd> for PidFd
fn from(fd: OwnedFd) -> Self
impl FromInner<InnerPidFd> for PidFd
fn from_inner(inner: InnerPidFd) -> PidFd
impl FromRawFd for PidFd
unsafe fn from_raw_fd(fd: RawFd) -> Self
impl IntoInner<InnerPidFd> for PidFd
fn into_inner(self) -> InnerPidFd
impl IntoRawFd for PidFd
fn into_raw_fd(self) -> RawFd
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
impl<T> Any for PidFd
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for PidFd
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for PidFd
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for PidFd
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SizeHint for PidFd
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for PidFd
impl<T, U> Into<U> for PidFd
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for PidFd
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for PidFd
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>