in reply to Re: Re: Mysterious Disapperance of file contents
in thread Mysterious Disapperance of file contents
....here open your counter file in read/write mode using same locking semantics as per the lockfile...then seek to 0, read the integer, add 1, seek to 0, write new value, close counter file, close lockfile, output new value to screen. don't unlock the counterfile/lockfile, just close them. this flushes the buffers and releases locks and closes in a fairly atomic fashion....that's another bug in the original code. Just remember that all this locking is only advisory, and programs not written to respect the locks will clobber it. Also, don't try to lock files over any network file systems, such as NFS,SMBFS.use Fcntl qw(:DEFAULT :flock); $lockfile = "counter.lck"; sysopen(COUNTERLOCK, $lockfile, O_RDONLY | O_CREAT) or die "can't open + $lockfile: $!"; flock(COUNTERLOCK, O_EXCL) or die "can't lock $lockfile: $!";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Mysterious Disapperance of file contents
by Abigail-II (Bishop) on Aug 29, 2003 at 11:02 UTC | |
|
Do I need to use sysopen for countfile locking?
by fraktalisman (Hermit) on Aug 29, 2003 at 13:27 UTC |