#[repr(transparent)]pub struct PidFd {
inner: PidFd,
}linux_pidfd #82971)Expand description
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: PidFdlinux_pidfd #82971)Implementations§
Source§impl PidFd
impl PidFd
Sourcepub fn kill(&self) -> Result<()>
🔬This is a nightly-only experimental API. (linux_pidfd #82971)
pub fn kill(&self) -> Result<()>
linux_pidfd #82971)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.
Sourcepub fn wait(&self) -> Result<ExitStatus>
🔬This is a nightly-only experimental API. (linux_pidfd #82971)
pub fn wait(&self) -> Result<ExitStatus>
linux_pidfd #82971)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.
Sourcepub fn try_wait(&self) -> Result<Option<ExitStatus>>
🔬This is a nightly-only experimental API. (linux_pidfd #82971)
pub fn try_wait(&self) -> Result<Option<ExitStatus>>
linux_pidfd #82971)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§
Source§impl AsFd for PidFd
impl AsFd for PidFd
Source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Source§impl FromInner<PidFd> for PidFd
impl FromInner<PidFd> for PidFd
fn from_inner(inner: InnerPidFd) -> PidFd
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 IntoInner<PidFd> for PidFd
impl IntoInner<PidFd> for PidFd
fn into_inner(self) -> InnerPidFd
Auto Trait Implementations§
impl Forget for PidFd
impl Freeze for PidFdwhere
I32NotAllOnes: Freeze,
impl Move for PidFd
impl RefUnwindSafe for PidFdwhere
I32NotAllOnes: RefUnwindSafe,
impl Send for PidFdwhere
I32NotAllOnes: Send,
impl Sync for PidFdwhere
I32NotAllOnes: Sync,
impl Unpin for PidFdwhere
I32NotAllOnes: Unpin,
impl UnsafeUnpin for PidFdwhere
I32NotAllOnes: UnsafeUnpin,
impl UnwindSafe for PidFdwhere
I32NotAllOnes: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize
#[doc(hidden)]const SIZE: usize
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize
#[doc(hidden)]const ALIGN: usize
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment
#[doc(hidden)]const ALIGNMENT: Alignment
sized_type_properties)Source§#[doc(hidden)]const IS_ZST: bool
#[doc(hidden)]const IS_ZST: bool
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout
#[doc(hidden)]const LAYOUT: Layout
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize
#[doc(hidden)]const MAX_SLICE_LEN: usize
sized_type_properties)[Self]. Read more