René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
flock in perl | ||
#!/usr/bin/perl use Fcntl qw (:flock); my $lock_file = 'dummy.lck'; open LOCKFILE, ">>$lock_file" or die "Cannot open $lock_file"; flock(LOCKFILE, LOCK_EX); print "file locked, going to sleep\n"; sleep 10; print "Woke up, releasing lock\n"; close LOCKFILE or die "Cannot close $lock_file";
flock calls are advisory. It won't affect any other script unless they use flock themselves as well. Here are five rules governing locks:
Thanks
Thanks to Charles Selig who reported a typo.
|