Let's say I have a list of open files (actually, file numbers):
import resource import fcntl def get_open_fds(): fds = [] soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE) for fd in range(3, soft): try: flags = fcntl.fcntl(fd, fcntl.F_GETFD) except IOError: continue fds.append(fd) return fds
Now I would like to get the names of these files. How can i do this?
EDIT
Just for clarification, for those who do this: fd is an integer. This is NOT a pointer file. Sorry for confusing the name, but the code is self-explanatory.
EDIT2
I hit it, I think, because my choice of fd means the file number. I just checked the documentation :
All functions in this module accept the file descriptor fd as the first argument. This can be an integer file descriptor, for example, returned by sys.stdin.fileno (), or a file object, such as sys.stdin, that provides fileno (), which returns a genuine file descriptor.
So fd really an integer. It can also be a file object, but in the general case, fd does not matter .name .
dangonfast
source share