develooper Front page | perl.beginners | Postings from March 2008

flock - exclusive file locking

Thread Next
From:
Dermot
Date:
March 17, 2008 13:55
Subject:
flock - exclusive file locking
Hi,

I have a cgi script that writes to a disk file. It would be safest if I can
get an exclusive lock on the file. I had a look at the opentut and believe I
have followed that the example there. Here's what I have

               sysopen my $fh, $file_path, O_WRONLY || die "can't open
$file_path: $!\n";
                flock($fh,LOCK_EX) or die "can't lock $file_path: $!\n";
                seek($fh, 0, 2);   # Append to file
                print $fh $status."\n";
                print STDERR "$0: $! $?\n";
                close($fh);

I am getting the error
"Inappropriate ioctl for device 0"

The worst part about this problem is that it seems completely erratic.
Sometimes the string is written to the file and sometimes not. Sometimes I
get an error and sometimes not but it never dies and the user will think the
data has been written to file! Does anyone see something wrong with the
snippet above or have any insights on file-clocking they could offer.

Thanx,
Dp.


Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About