in reply to File Locking Problem

For this sort of problem, a separate "semaphore" file is a handy gimmick -- the semaphore file has no content (nothing to lose when you clobber it), and it's sole purpose is to establish a lock. So long as all the processes using a shared resource work with the same semaphore file, the locking will do what you want without ever damaging or losing data. (Also, you can use the same semaphore design for locking resources that don't happen to be files.)

I had occasion to post a nice semaphore module here (in another SoPW thread). I use this myself a lot, and it has never failed me.