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