If performance matters, this is always a good idea!
For what you want to do, getting a "read lock" on LOG, basically means nothing. You need an exclusive lock. There is no need to get any kind of lock on the temp file - should be a unique file anyway. I mean if it is a unique file, for your own access, nobody else is going to mess with it.
You haven't explained much (actually nothing) about what LOG does in terms of IPC except that this file is used for IPC (Inter Process Communication).
There is a difference between "guaranteed to work all of the time" and "very high probability of working".
My question about interference between flock() and rename() is still open.
If the file is closed, the lock is released. You cannot have a lock unless the file is open. You cannot rename x=>y unless y doesn't exist. If your process relies upon a "write" lock on y, this won't work (all of the time) because you have to delete "y" before re-naming x=>y. If your OS allows x to replace an existing file y, then I'd like to see a Perl example.
rename as like all file operations, can fail -- check the return status.
In reply to Re^6: Trying to optimize reading/writing of large text files.
by Marshall
in thread Trying to optimize reading/writing of large text files.
by nikkimouse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |