in reply to perl 5+ and flock
use strict; use warnings; open FILE, ">x.txt" or die "Cannot create test file: $!"; print FILE "TEXT\n"; close FILE; my $pid = fork(); if ($pid == 0) { # in the child open FC, "<x.txt" or die "Can not open test file"; if (flock(FC, 2) < 0) { die "Can not lock" } for (0..10) { sleep 1; print "$_\n"; die "No lock" if ! -s "x.txt"; } close FC; } else { sleep 5; open FC2, ">x.txt" or print "Can not create file\n"; close FC2; sleep(5); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: perl 5+ and flock
by Anonymous Monk on Dec 15, 2003 at 07:52 UTC |