Section: Linux Programmer's Manual (2)
pidfd_getfd - obtain a duplicate of another process's file descriptor
int pidfd_getfd(int pidfd, int targetfd, unsigned int flags);
system call allocates a new file descriptor in the calling process.
This new file descriptor is a duplicate of an existing file descriptor,
in the process referred to by the PID file descriptor
The duplicate file descriptor refers to the same open file description (see
as the original file descriptor in the process referred to by
The two file descriptors thus share file status flags and file offset.
Furthermore, operations on the underlying file object
(for example, assigning an address to a socket object using
can equally be performed via the duplicate file descriptor.
The close-on-exec flag
is set on the file descriptor returned by
argument is reserved for future use.
Currently, it must be specified as 0.
Permission to duplicate another process's file descriptor
is governed by a ptrace access mode
returns a file descriptor (a nonnegative integer).
On error, -1 is returned and
is set to indicate the cause of the error.
is not a valid PID file descriptor.
is not an open file descriptor in the process referred to by
is not 0.
The per-process limit on the number of open file descriptors has been reached
(see the description of
The system-wide limit on the total number of open files has been reached.
The calling process did not have
over the process referred to by
The process referred to by
does not exist
(i.e., it has terminated and been waited on).
first appeared in Linux 5.6.
is Linux specific.
Currently, there is no glibc wrapper for this system call; call it using
For a description of PID file descriptors, see
The effect of
is similar to the use of
messages described in
but differs in the following respects:
In order to pass a file descriptor using an
the two processes must first establish a UNIX domain socket connection.
The use of
requires cooperation on the part of the process whose
file descriptor is being copied.
By contrast, no such cooperation is necessary when using
The ability to use
is restricted by a
ptrace access mode check.
This page is part of release 5.07 of the Linux
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at