2010-12-13 03:59:39 -04:00
|
|
|
"""When called as a script, print a comma-separated list of the open
|
2013-09-01 05:22:41 -03:00
|
|
|
file descriptors on stdout.
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
fd_stats.py: check all file descriptors
|
|
|
|
fd_status.py fd1 fd2 ...: check only specified file descriptors
|
|
|
|
"""
|
2010-12-13 03:59:39 -04:00
|
|
|
|
|
|
|
import errno
|
|
|
|
import os
|
2013-08-21 20:58:04 -03:00
|
|
|
import stat
|
2013-09-01 05:22:41 -03:00
|
|
|
import sys
|
2010-12-13 03:59:39 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2011-02-21 17:55:48 -04:00
|
|
|
fds = []
|
2013-09-01 05:22:41 -03:00
|
|
|
if len(sys.argv) == 1:
|
|
|
|
try:
|
|
|
|
_MAXFD = os.sysconf("SC_OPEN_MAX")
|
|
|
|
except:
|
|
|
|
_MAXFD = 256
|
|
|
|
test_fds = range(0, _MAXFD)
|
|
|
|
else:
|
|
|
|
test_fds = map(int, sys.argv[1:])
|
|
|
|
for fd in test_fds:
|
2011-02-21 17:55:48 -04:00
|
|
|
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)))
|