| Next | System Programming in Perl | 39 |
use Fcntl ':flock';
my $important_file = "/etc/passwd";
my $semaphore = "/etc/passwd.sem";
open my($sem), "+>>", $semaphore or die ...;
if (flock $sem, LOCK_EX) {
# ... open the file
# ... modify the file
# ... close the file
}
close $sem;
| Next | ![]() |
39 |