| 1 | #!/usr/bin/env python2
 | 
| 2 | from __future__ import print_function
 | 
| 3 | """
 | 
| 4 | show_fd_table.py -- Uses Linux-specific proc interface
 | 
| 5 | """
 | 
| 6 | 
 | 
| 7 | import os
 | 
| 8 | import sys
 | 
| 9 | 
 | 
| 10 | 
 | 
| 11 | def main(argv):
 | 
| 12 |     d = '/proc/self/fd/'
 | 
| 13 |     for fd in os.listdir(d):
 | 
| 14 |         path = os.path.join(d, fd)
 | 
| 15 |         try:
 | 
| 16 |             connected_to = os.readlink(path)
 | 
| 17 |         except OSError as e:
 | 
| 18 |             print('%s %s' % (fd, e))
 | 
| 19 |         else:
 | 
| 20 |             print('%s %s' % (fd, connected_to))
 | 
| 21 | 
 | 
| 22 | 
 | 
| 23 | if __name__ == '__main__':
 | 
| 24 |     try:
 | 
| 25 |         main(sys.argv)
 | 
| 26 |     except RuntimeError as e:
 | 
| 27 |         print >> sys.stderr, 'FATAL: %s' % e
 | 
| 28 |         sys.exit(1)
 |