in reply to singleton lock not reliable
First thing I thought of was shared memory. In IPC::Shareable, if one attempts to create a shared memory segment that has already been created in a separate process with exclusive set, the second process will croak(). So what I did is add a graceful flag to its options, and when set, the second process that tries to create the exclusive segment simply exits gracefully with no noise or anything. Observe:
lock.pl:
use warnings; use strict; use IPC::Shareable; tie my $lock, 'IPC::Shareable', { key => 'LOCK', create => 1, exclusive => 1, destroy => 1, graceful => 1 }; $lock = $$; print "procID: $lock\n"; sleep 5;
Run it in one window:
spek@scelia ~/scratch $ perl lock.pl procID: 21241
...it sleeps for a few seconds, during which we run it in the second window:
spek@scelia ~/repos/ipc-shareable $ perl ~/scratch/lock.pl spek@scelia ~/repos/ipc-shareable $
...it exited before it printed anything. After the five second sleep in proc one is done, run it in window two:
spek@scelia ~/repos/ipc-shareable $ perl ~/scratch/lock.pl procID: 21339
So, in essence, this question prompted me to update the distribution to handle your very issue, ummm, well, gracefully. I just published it, so it may not yet be available at your mirror. Version 1.01 has the new 'graceful' feature.