STINNER Victor <vstin...@python.org> added the comment:
> On Linux, _posixsubprocess lists the content of /proc/self/fd/ to only close > open file descriptor, after fork() and before exec(). This code is specific to Linux because it uses the SYS_getdents64 syscall. FreeBSD has a similar concept using /dev/fd "file-descriptor file system". See fdescfs manual page: https://www.freebsd.org/cgi/man.cgi?query=fdescfs&sektion=5 I'm not sure how it is supposed to work. When I open a file in Python, I don't see its file descriptor in /dev/fd: vstinner@freebsd$ python3 Python 3.6.9 (default, Aug 8 2019, 01:16:42) >>> import os >>> os.listdir("/dev/fd") ['0', '1', '2'] >>> f=open("/etc/motd") >>> os.listdir("/dev/fd") ['0', '1', '2'] >>> f.fileno() 3 >>> os.set_inheritable(f.fileno(), True) >>> os.listdir("/dev/fd") ['0', '1', '2'] >>> import sys, subprocess >>> rc=subprocess.call([sys.executable, "-c", "import os; >>> print(os.listdir('/dev/fd')); print(os.fstat(3))"], close_fds=False) ['0', '1', '2'] os.stat_result(st_mode=33188, st_ino=321134, st_dev=83, st_nlink=1, st_uid=0, st_gid=0, st_size=899, st_atime=1568014491, st_mtime=1566390614, st_ctime=1566390614) The file descriptor 3 is not listed in /dev/fd/. It is inherited: fstat(3) in a child process doesn't fail and it's not listed in /dev/fd/ in the child process. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38061> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com