is file open in system ? - other than lsof
Thomas Guettler
hv at tbz-pariv.de
Thu Apr 17 10:56:02 EDT 2008
bvidinli schrieb:
> is there a way to find out if file open in system ? -
> please write if you know a way other than lsof. because lsof if slow for me.
> i need a faster way.
> i deal with thousands of files... so, i need a faster / python way for this.
> thanks.
>
>
On Linux there are symlinks from /proc/PID/fd to the open
files. You could use this:
#!/usr/bin/env python
import os
pids=os.listdir('/proc')
for pid in sorted(pids):
try:
int(pid)
except ValueError:
continue
fd_dir=os.path.join('/proc', pid, 'fd')
for file in os.listdir(fd_dir):
try:
link=os.readlink(os.path.join(fd_dir, file))
except OSError:
continue
print pid, link
--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
More information about the Python-list
mailing list