MitchInOmaha has asked for the wisdom of the Perl Monks concerning the following question:
I'm looking for a way to synchronize the four Perl processes to keep them from each trying to process the same file.
My original plan was to File::Copy::move() the files to a local /tmp folder, and only the first guy to move the file would win (if your move failed, you just move on to the next file).
Turns out this fails because File::Copy::move() is actually implemented as a multi-step copy/set-attribs/delete process that doesn't have any file locking protecting it. I ended up with multiple processes each copying the same file, one would delete the source file, and the other would be just getting done and try to stat() the original file (to set the atime and mtime of the new copy) and there'd be no original file.
How can I keep these four processes (each on different servers, incidentally) from clashing and trying to process the same file?
-- Mitch
|
|---|