pub struct PidFd { /* private fields */ }🔬This is a nightly-only experimental API. (
linux_pidfd #82971)Available on Linux only.
Expand description
此类型表示引用进程的文件描述符。
PidFd 可以通过设置 Command 和 create_pidfd 上的相应选项来获得。随后,可以通过调用 pidfd 或 take_pidfd 从 Child 中检索创建的 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
.take_pidfd()
.expect("Failed to retrieve pidfd");
// 当 `pidfd` 关闭时,文件描述符将被关闭。Run有关详细信息,请参见 pidfd_open(2) 的手册页。