2010-12-13 03:59:39 -04:00
|
|
|
"""When called as a script, print a comma-separated list of the open
|
|
|
|
file descriptors on stdout."""
|
|
|
|
|
|
|
|
import errno
|
|
|
|
import os
|
2013-08-21 20:58:04 -03:00
|
|
|
import stat
|
2010-12-13 03:59:39 -04:00
|
|
|
|
|
|
|
try:
|
|
|
|
_MAXFD = os.sysconf("SC_OPEN_MAX")
|
|
|
|
except:
|
|
|
|
_MAXFD = 256
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2011-02-21 17:55:48 -04:00
|
|
|
fds = []
|
|
|
|
for fd in range(0, _MAXFD):
|
|
|
|
try:
|
|
|
|
st = os.fstat(fd)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno == errno.EBADF:
|
|
|
|
continue
|
|
|
|
raise
|
|
|
|
# Ignore Solaris door files
|
2013-08-21 20:58:04 -03:00
|
|
|
if not stat.S_ISDOOR(st.st_mode):
|
2011-02-21 17:55:48 -04:00
|
|
|
fds.append(fd)
|
|
|
|
print(','.join(map(str, fds)))
|