Skip to content

Commit 000e800

Browse files
committed
Clarify fd inheritance: fork vs exec in both docs
- mkstemp(): Clarify non-inheritance applies to exec, add link to fd_inheritance - os module: Explain that non-inheritable fds remain accessible after fork() but close on exec() Addresses feedback from vstinner.
1 parent 090d058 commit 000e800

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Doc/library/os.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,11 @@ can be inherited by child processes. Since Python 3.4, file descriptors
19691969
created by Python are non-inheritable by default.
19701970

19711971
On UNIX, non-inheritable file descriptors are closed in child processes at the
1972-
execution of a new program, other file descriptors are inherited.
1972+
execution of a new program (via :func:`os.execl` and related functions), but
1973+
they remain accessible after :func:`os.fork` until an exec call occurs. In other
1974+
words, a forked child process can still use the file descriptor, but it will be
1975+
closed if that child process calls exec to run a new program. Inheritable file
1976+
descriptors are inherited across both fork and exec calls.
19731977

19741978
On Windows, non-inheritable handles and file descriptors are closed in child
19751979
processes, except for standard streams (file descriptors 0, 1 and 2: stdin, stdout

0 commit comments

Comments
 (0)