1 use crate::fd::OwnedFd;
2 use crate::process::Pid;
3 use crate::{backend, io};
4
5 bitflags::bitflags! {
6 /// `PIDFD_*` flags for use with [`pidfd_open`].
7 ///
8 /// [`pidfd_open`]: crate::process::pidfd_open
9 #[repr(transparent)]
10 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
11 pub struct PidfdFlags: backend::c::c_uint {
12 /// `PIDFD_NONBLOCK`.
13 const NONBLOCK = backend::c::PIDFD_NONBLOCK;
14
15 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
16 const _ = !0;
17 }
18 }
19
20 /// `syscall(SYS_pidfd_open, pid, flags)`—Creates a file descriptor for a
21 /// process.
22 ///
23 /// # References
24 /// - [Linux]
25 ///
26 /// [Linux]: https://man7.org/linux/man-pages/man2/pidfd_open.2.html
27 #[inline]
pidfd_open(pid: Pid, flags: PidfdFlags) -> io::Result<OwnedFd>28 pub fn pidfd_open(pid: Pid, flags: PidfdFlags) -> io::Result<OwnedFd> {
29 backend::process::syscalls::pidfd_open(pid, flags)
30 }
31