peps: 425f831fddf7 (original) (raw)

Mercurial > peps

changeset 4978:425f831fddf7

PEP 446: enhance the Rationale to take into account Cameron Simpson's remarks * mention the name of the close-on-exec flag: HANDLE_FLAG_INHERIT, O_CLOEXEC * mention the name of the blocking flag: O_NONBLOCK * explain that file attributes are duplicated at fork

Victor Stinner victor.stinner@gmail.com
date Sat, 06 Jul 2013 14:27:23 +0200
parents 39553edc98e2
children cc4da4be3838
files pep-0446.txt
diffstat 1 files changed, 21 insertions(+), 7 deletions(-)[+] [-] pep-0446.txt 28

line wrap: on

line diff

--- a/pep-0446.txt +++ b/pep-0446.txt @@ -27,14 +27,25 @@ The inheritance of file descriptors in c on each file descriptor using a close-on-exec flag. By default, the close-on-exec flag is not set. -On Windows, file descriptors are not inherited if the -bInheritHandles parameter of the CreateProcess() function is -FALSE, even if the close-on-exec flag is not set. +On Windows, the close-on-exec flag is HANDLE_FLAG_INHERIT. File +descriptors are not inherited if the bInheritHandles parameter of +the CreateProcess() function is FALSE, even if the +HANDLE_FLAG_INHERIT flag is set. If bInheritHandles is TRUE, +only file descriptors with HANDLE_FLAG_INHERIT flag set are +inherited, others are not. -On UNIX, file descriptors with the close-and-exec flag set are closed at -the execution of a new program (ex: when calling execv()). The flag -has no effect on fork(), all file descriptors are inherited by the -child process. +On UNIX, the close-on-exec flag is O_CLOEXEC. File descriptors with +the O_CLOEXEC flag set are closed at the execution of a new program +(ex: when calling execv()). + +The O_CLOEXEC flag has no effect on fork(), all file descriptors +are inherited by the child process. Futhermore, most properties file +descriptors are shared between the parent and the child processes, +except file attributes which are duplicated (O_CLOEXEC is the only +file attribute). Setting O_CLOEXEC flag of a file descriptor in the +child process does not change the O_CLOEXEC flag of the file +descriptor in the parent process. + Issues of the inheritance of file descriptors --------------------------------------------- @@ -62,6 +73,9 @@ operation would block. By default, newly created sockets are blocking. Setting the non-blocking mode requires additional system calls. +On UNIX, the blocking flag is O_NONBLOCK: a pipe and a socket are +non-blocking if the O_NONBLOCK flag is set. + Setting flags at the creation of the file descriptor ----------------------------------------------------