in reply to Re^2: Easiest way to protect process from duplication.
in thread [Solved]Easiest way to protect process from duplication.
The unlink comes before any unlock or close. Otherwise you get even more race scenarios (on Windows you must actually close before being able to delete) The open is an open with create (O_CREAT), otherwise unlinking makes the next program invocation fail but without exclusive (O_EXCL) otherwise we are getting into a different locking system (with even more problems).This type of open is what you get if you do a plain open($fh, ">", $file) in perl.open lock unlink exit
Now you can get as sequence:
Now process B and C are running simultaneously with locks on different files of which only one is visible in the filesystemprocess A: open (and create) process A: lock process B: open (same file so no create) process A: unlink process A: exit (implicit unlock) process B: lock (on the file A just deleted since B still has an open +handle on it) process C: open (and create a new file with the old path name) process C: lock (on the new file)
|
---|