in reply to Re: File locking
in thread File locking
And here's the output it produces when run on my system: Can't flock flock.test in child: Resource temporarily unavailable at flock.pl line 18. However, this behavior is probably system dependent, so physi and I are likely both right.#!/usr/local/bin/perl -w use strict; use Fcntl qw/:flock/; my $file = 'flock.test'; -e $file or open(FILE, ">$file") or die "Can't create $file: $!"; if (fork) { open(FILE, "<$file") or die "Can't open $file for reading in paren +t: $!"; flock(FILE, LOCK_EX) or die "Can't flock $file in parent: $!"; wait; } else { sleep 1; open(FILE, "<$file") or die "Can't open $file for reading in child +: $!"; flock(FILE, LOCK_EX|LOCK_NB) or die "Can't flock $file in child: $ +!"; }
|
|---|