How to programmatically discern whether or not a file is use
Gerhard Häring
gh at ghaering.de
Sat May 31 12:07:52 EDT 2003
Techead wrote:
> How can a Python program determine whether or not a file
> is use by another process? [...]
There is no function in the standard library. There are
system-dependent tools that you could interface using os.popen and
friends. If you want to get fancy, you can grab their source code and
implement a library in C.
On Linux the tool you'll want is 'fuser':
#v+
gerhard at mephisto:/tmp$ fuser /var/log/messages
gerhard at mephisto:/tmp$ su
Password:
mephisto:/tmp# fuser /var/log/messages
/var/log/messages: 395
mephisto:/tmp# ps ax|grep 395
395 ? S 0:00 /sbin/syslogd
mephisto:/tmp# exit
gerhard at mephisto:/tmp$
#v-
As you see this will need superuser privileges on some systems.
Gerhard
--
http://ghaering.de/
More information about the Python-list
mailing list