in reply to perl 5+ and flock

I thought the issue with the Sun compiler and linker does not apply to the Mac. You could write a little script that checks whether the version of Perl installed on the Mac OS-X can do 'flock' correctly or not.

The following is a little script I wrote for testing flocks. The idea is to have one process locks a file, and then have another process trying to truncate it. If the file size gets trimmed when the file is supposed to be locked, then you know there is a problem with flock. It turns out that the version of Perl I am using on the Sun box does not implement flock correctly.
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

    AFAICT your test script only demonstrates that flock is advisory.