当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Rust PidFd用法及代码示例

本文简要介绍rust语言中 Struct std::os::linux::process::PidFd 的用法。

用法

pub struct PidFd { /* fields omitted */ }

此类型表示引用进程的文件说明符。

PidFd 可以通过在 Command 上使用 create_pidfd 设置相应的选项来获得。随后,可以通过调用 pidfd take_pidfd Child 中检索创建的 pidfd。

例子:

#![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");

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

有关详细信息,请参阅 pidfd_open(2) 的手册页。

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 Struct std::os::linux::process::PidFd。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。