Well, this probably won't be helpful, but ...
flock is not going to save you if the 'other' apps won't
play nice. Likewise, unless all your apps respect the
SEMAPHORE flag (e.g.:
while ( -s $SEMAPHORE ) {
print STDERR "lock found waiting\n" if $debug > 10;
sleep 5;
}
flocking it won't do much. Of course, this
implies that $SEMAPHORE is a well known name (/tmp/myapp.lck),
not /tmp/mlock$$.lck - unless other versions can predict
the name and check if it exists, (I'm guessing $file
is the useful name and the file that gets 'wiped' now
and then) your lock/semaphore isn't going to help. It seems
your code would allow 2 instances to mess w/ $file if
they each had different $tempfile instances. It should
be that they have one $SEMAPHORE to work w/, check the
existence of, etc.
Sorry, I don't recall your other
posts, but you might also do your self some good by
having the 'rename' preceeded by a debug "about to
rename $tempfile to $file (I'm $this instance)" so you
can see who is doing the wiping in hopes of pinpointing
where your lock/semaphore goes a stray. As I read it, though
your flocking isn't really giving you exclusive access
for multiple instances of that code, or for anybody
else, unless they're using the same $tempfile.
a