[NTLUG:Discuss] Flock file hanging around
Stuart Johnston
saj at thecommune.net
Mon Jan 28 15:10:55 CST 2013
On 1/28/2013 2:20 PM, Steve Litt wrote:
> Let me ask you a question: What's the harm if /var/lock/mylock remains
> afterward? From my understanding, after the lock terminates, the file
> is just another file. And if something else locks it, it re-assumes its
> role as a lockfile.
Avoiding clutter, I guess?
There is a nifty trick in Perl where a script locks itself by using the
internal file handle, DATA. This only works when a script always runs
from the same location but it avoid the extra file.
use Fcntl qw(:flock);
flock(DATA, LOCK_EX | LOCK_NB) or die 'Cannot lock';
#do stuff...
__DATA__
More information about the Discuss
mailing list