1 .\" Copyright (c) 2020 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .TH PIDFD_GETFD 2 2022-09-09 "Linux man-pages (unreleased)"
7 pidfd_getfd \- obtain a duplicate of another process's file descriptor
10 .RI ( libc ", " \-lc )
13 .BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */"
14 .B #include <unistd.h>
16 .BI "int syscall(SYS_pidfd_getfd, int " pidfd ", int " targetfd ,
17 .BI " unsigned int " flags );
21 glibc provides no wrapper for
23 necessitating the use of
28 system call allocates a new file descriptor in the calling process.
29 This new file descriptor is a duplicate of an existing file descriptor,
31 in the process referred to by the PID file descriptor
34 The duplicate file descriptor refers to the same open file description (see
36 as the original file descriptor in the process referred to by
38 The two file descriptors thus share file status flags and file offset.
39 Furthermore, operations on the underlying file object
40 (for example, assigning an address to a socket object using
42 can equally be performed via the duplicate file descriptor.
44 The close-on-exec flag
48 is set on the file descriptor returned by
53 argument is reserved for future use.
54 Currently, it must be specified as 0.
56 Permission to duplicate another process's file descriptor
57 is governed by a ptrace access mode
58 .B PTRACE_MODE_ATTACH_REALCREDS
64 returns a file descriptor (a nonnegative integer).
65 On error, \-1 is returned and
67 is set to indicate the error.
72 is not a valid PID file descriptor.
76 is not an open file descriptor in the process referred to by
84 The per-process limit on the number of open file descriptors has been reached
85 (see the description of
91 The system-wide limit on the total number of open files has been reached.
94 The calling process did not have
95 .B PTRACE_MODE_ATTACH_REALCREDS
98 over the process referred to by
102 The process referred to by
105 (i.e., it has terminated and been waited on).
108 first appeared in Linux 5.6.
109 .\" commit 8649c322f75c96e7ced2fec201e123b2b073bf09
114 For a description of PID file descriptors, see
119 is similar to the use of
121 messages described in
123 but differs in the following respects:
125 In order to pass a file descriptor using an
128 the two processes must first establish a UNIX domain socket connection.
132 requires cooperation on the part of the process whose
133 file descriptor is being copied.
134 By contrast, no such cooperation is necessary when using
140 .B PTRACE_MODE_ATTACH_REALCREDS
141 ptrace access mode check.