Jennifer Pioch wrote:
> Any advice on a good way to implement a multiple readers/single writer
> lock in a ksh shell script? Multiple scripts should read from a file
> but only a single one should be allowed to update or replace the file.

The only times when I ever tried anything even close to that, I did not
really bother, as any of the files I worked with was either replaced
entirely on each write, or just appended to.

The first instance I made atomic by doing

        print "$value" > $file. && mv $file. $file

because '>' starts with truncating the existing file, which
could theoretically lead to a race condition resulting in
reading an empty file.

Other processes reading these files either access the old
(unlinked) file, or the new.

For a full-fledged read/write lock mechanism, and you really need
to suspend any reads while writing,  you need to keep track
of the number of active readers - maybe something for a discipline
function.

Cheers,
Henk

Reply via email to