from perldoc -f flock
Two potentially non-obvious but traditional flock semantics are that it waits indefinitely until the lock is granted, and that its locks merely advisory. Such discretionary locks are more flexible, but offer fewer guarantees. This means that programs that do not also use flock may modify files locked with flock.
So you need to use same locking mechanism in all processes interested in locking the file, in order to ensure that files gets locked properly.
All file locking algo works like this:
While (file_is_locked()) {
wait;
}
lock_the file();
Do_somthing_on_file;
unlock_the_file();
Its up to you to decide, what you mean when you say 'lock_the file();' I suggest to create lock file, so 'file_is_locked()' will mean checking existance of .lock file.
HTH;
---------- Post updated at 05:45 PM ---------- Previous update was at 05:44 PM ----------
Quote:
Originally Posted by
pludi
Perl's flock() does give you a lock on a file, if you use LOCK_EX, and all other processes use that mechanism too. If they don't, you're out of luck. If you don't want the file to be modified, change the permissions to read-only for everyone else (but root will still be able to modify it).
That wont help if, all processes interested in having lock on perticular file, runs with same user id.