OILS / spec / bin / show_fd_table.py View on Github | oilshell.org

28 lines, 19 significant
1#!/usr/bin/env python2
2from __future__ import print_function
3"""
4show_fd_table.py -- Uses Linux-specific proc interface
5"""
6
7import os
8import sys
9
10
11def 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
23if __name__ == '__main__':
24 try:
25 main(sys.argv)
26 except RuntimeError as e:
27 print >> sys.stderr, 'FATAL: %s' % e
28 sys.exit(1)