(original) (raw)

changeset: 4978:425f831fddf7 user: Victor Stinner victor.stinner@gmail.com date: Sat Jul 06 14:27:23 2013 +0200 files: pep-0446.txt description: 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 diff -r 39553edc98e2 -r 425f831fddf7 pep-0446.txt --- a/pep-0446.txt Thu Jul 04 22:10:39 2013 +0200 +++ b/pep-0446.txt Sat Jul 06 14:27:23 2013 +0200 @@ -27,14 +27,25 @@ 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 @@ 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 ---------------------------------------------------- /victor.stinner@gmail.com