Unable to lock a file to stop sendmail writing to it
- From: "GarfGarf" <garfield_99999@xxxxxxxxx>
- Date: 20 Jul 2006 01:54:24 -0700
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 !
.
- Follow-Ups:
- Re: Unable to lock a file to stop sendmail writing to it
- From: Gunnar Hjalmarsson
- Re: Unable to lock a file to stop sendmail writing to it
- From: anno4000
- Re: Unable to lock a file to stop sendmail writing to it
- Prev by Date: Re: libstdc++ problem with ExtUtils::MakeMaker
- Next by Date: Re: Unable to lock a file to stop sendmail writing to it
- Previous by thread: FAQ 1.9 How does Perl compare with other languages like Java, Python, REXX, Scheme, or Tcl?
- Next by thread: Re: Unable to lock a file to stop sendmail writing to it
- Index(es):
Relevant Pages
|
|