Function rustix::process::pidfd_getfd::pidfd_getfd

source ·
pub fn pidfd_getfd<Fd: AsFd>(
    pidfd: Fd,
    targetfd: ForeignRawFd,
    flags: PidfdGetfdFlags,
) -> Result<OwnedFd>
Expand description

syscall(SYS_pidfd_getfd, pidfd, flags)—Obtain a duplicate of another process’ file descriptor.

§References

§Warning

This function is generally safe for the calling process, but it can impact the target process in unexpected ways. If you want to ensure that Rust I/O safety assumptions continue to hold in the target process, then the target process must have communicated the file description number to the calling process from a value of a type that implements AsRawFd, and the target process must not drop that value until after the calling process has returned from pidfd_getfd.

When pidfd_getfd is used to debug the target, or the target is not a Rust application, or pidfd_getfd is used in any other way, then extra care should be taken to avoid unexpected behaviour or crashes.

For further details, see the references above.