Debian Codegraph @

upstream/debian-unstable/man2/F_GETFD.2const

raw
1 .\" Copyright, the authors of the Linux man-pages project
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .TH F_GETFD 2const 2026-01-05 "Linux man-pages 6.18"
6 .SH NAME
7 F_GETFD,
8 F_SETFD
9 \-
10 get/set file descriptor flags
11 .SH LIBRARY
12 Standard C library
13 .RI ( libc ,\~ \-lc )
14 .SH SYNOPSIS
15 .nf
16 .B #include <fcntl.h>
17 .P
18 .BI "int fcntl(int " fd ", F_GETFD);"
19 .BI "int fcntl(int " fd ", F_SETFD, int " arg );
20 .fi
21 .SH DESCRIPTION
22 These operations manipulate the flags associated with
23 a file descriptor.
24 Currently, only one such flag is defined:
25 .BR FD_CLOEXEC ,
26 the close-on-exec flag.
27 If the
28 .B FD_CLOEXEC
29 bit is set,
30 the file descriptor will automatically be closed during a successful
31 .BR execve (2).
32 (If the
33 .BR execve (2)
34 fails, the file descriptor is left open.)
35 If the
36 .B FD_CLOEXEC
37 bit is not set, the file descriptor will remain open across an
38 .BR execve (2).
39 .TP
40 .B F_GETFD
41 Return (as the function result) the file descriptor flags;
42 .I arg
43 is ignored.
44 .TP
45 .B F_SETFD
46 Set the file descriptor flags to the value specified by
47 .IR arg .
48 .SH RETURN VALUE
49 .TP
50 .B F_GETFD
51 Value of file descriptor flags.
52 .TP
53 .B F_SETFD
54 Zero.
55 .P
56 On error, \-1 is returned, and
57 .I errno
58 is set to indicate the error.
59 .SH ERRORS
60 See
61 .BR fcntl (2).
62 .SH STANDARDS
63 POSIX.1-2024.
64 .SH HISTORY
65 SVr4,
66 4.3BSD,
67 POSIX.1-1988.
68 .SH CAVEATS
69 In multithreaded programs, using
70 .BR fcntl (2)
71 .B F_SETFD
72 to set the close-on-exec flag at the same time as another thread performs a
73 .BR fork (2)
74 plus
75 .BR execve (2)
76 is vulnerable to a race condition that may unintentionally leak
77 the file descriptor to the program executed in the child process.
78 See the discussion of the
79 .B O_CLOEXEC
80 flag in
81 .BR open (2)
82 for details and a remedy to the problem.
83 .SH SEE ALSO
84 .BR fcntl (2)