On Fri, Jun 10, 2005 at 10:40:34AM +1000, Harvey, Allan AC wrote:
> Hi all,
> Can anyone offer a method of testing if a file is open
> by another process from within in a script?
Depends upon the language of the script. First have a look at
man 2 flock
and see if this function is what you want. Scripts could either
call a utility program to use flock(2), or better (as is the
case with Perl) have
wrapper functions around it. The "Programming Perl" book
advises that flock() is not safe on a network
file system e.g. NFS.
I have reused the Python Mailman locking module in some of my
own Python scripts by lifting this module file from the
Mailman source and making a minor modification.
You can extract a copy of this LockFile.py version from
or get the original from http://www.list.org/
Even if you don't plan using Python, I think
you will find reading this source file and
experimenting with it informative
concerning file locking.