G
GarfGarf
Hi all,
I am trying to write a script that reads a mailbox that sendmail
updates, but I want to be able to lock the file, read the file, empty
the file and unlock the file again.
The problem I have is that locking doesn't seem to work. As I can't
lock the file, sendmail writes into the file while i'm writing and that
causes all sorts of problems.
Here are some things I tried:-
sysopen(FH,"/tmp/file",O_EXCL | O_RDWR) || die "Error:$!";
print "File opened\n";
sleep 20;
close FH;
or
use Fcntl ':flock'; # import LOCK_* constants
open(FILE,"</tmp/file") || die $!;
flock(FILE,LOCK_EX);
sleep 20;
close FILE;
each one of those should lock the file, and hold the lock for 20
seconds.
However during that 20 seconds I can still run date >> /tmp/file
and it gets written to.
This happens both on solaris and linux.
Help !
I am trying to write a script that reads a mailbox that sendmail
updates, but I want to be able to lock the file, read the file, empty
the file and unlock the file again.
The problem I have is that locking doesn't seem to work. As I can't
lock the file, sendmail writes into the file while i'm writing and that
causes all sorts of problems.
Here are some things I tried:-
sysopen(FH,"/tmp/file",O_EXCL | O_RDWR) || die "Error:$!";
print "File opened\n";
sleep 20;
close FH;
or
use Fcntl ':flock'; # import LOCK_* constants
open(FILE,"</tmp/file") || die $!;
flock(FILE,LOCK_EX);
sleep 20;
close FILE;
each one of those should lock the file, and hold the lock for 20
seconds.
However during that 20 seconds I can still run date >> /tmp/file
and it gets written to.
This happens both on solaris and linux.
Help !