PidFd in std::os::linux::process - Rust (original) (raw)
pub struct PidFd { /* private fields */ }
🔬This is a nightly-only experimental API. (linux_pidfd
#82971)
Available on Linux only.
Expand description
This type represents a file descriptor that refers to a process.
A PidFd
can be obtained by setting the corresponding option on Commandwith 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.
🔬This is a nightly-only experimental API. (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.
🔬This is a nightly-only experimental API. (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 it will not return an ExitStatus
if the child has already been reaped. Instead an error will be returned.
🔬This is a nightly-only experimental API. (linux_pidfd
#82971)
Attempts to collect the exit status of the child if it has already exited.
Unlike Child::try_wait this method will return an Error if the child has already been reaped.