The_Dj has asked for the wisdom of the Perl Monks concerning the following question:
Hi, Monks.
I can't believe no-one has solved this so it must be that my google-fu has failed me.
Simple lockfile for concurrency.
The problem is...
Sometimes the process needs to be killed, and for that someone needs to read that file.
Notepad works fine, but for some reason the people who do this try to open the file in vim (despite being windows people :-|)
Vim honors the exclusive lock, and shows no content.
Vim will read the file if it's only a shared lock.
If I just flock (LF,LOCK_SH); the exclusive lock remains.
But if I flock (LF,LOCK_UN); flock(LF,LOCK_SH); then I risk a race condition.
A random stab at flock (LF,LOCK_UN|LOCK_SH) didn't work either.
I can't install extra modules because reasons.
Thanks for any help!
I can't believe no-one has solved this so it must be that my google-fu has failed me.
Simple lockfile for concurrency.
This is on Windows 2003/ActivePerl 5.8, and the locking works.use Fcntl ':flock'; open (LF,'>>',$file); flock (LF,LOCK_EX|LOCK_NB) or die "Just one at a time, please"; select LF; $|=1; print "$$\n"; select STDOUT; ...snip... truncate LF,0; close LF; unlink $file; __END__
The problem is...
Sometimes the process needs to be killed, and for that someone needs to read that file.
Notepad works fine, but for some reason the people who do this try to open the file in vim (despite being windows people :-|)
Vim honors the exclusive lock, and shows no content.
Vim will read the file if it's only a shared lock.
If I just flock (LF,LOCK_SH); the exclusive lock remains.
But if I flock (LF,LOCK_UN); flock(LF,LOCK_SH); then I risk a race condition.
A random stab at flock (LF,LOCK_UN|LOCK_SH) didn't work either.
I can't install extra modules because reasons.
Thanks for any help!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: File locking; downgrade an exclusive to a shared lock
by davido (Cardinal) on Jul 12, 2013 at 03:20 UTC | |
by The_Dj (Beadle) on Jul 12, 2013 at 04:30 UTC | |
Re: File locking; downgrade an exclusive to a shared lock
by Anonymous Monk on Jul 12, 2013 at 08:41 UTC | |
Re: File locking; downgrade an exclusive to a shared lock
by mtmcc (Hermit) on Jul 12, 2013 at 08:57 UTC | |
Re: File locking; downgrade an exclusive to a shared lock
by Anonymous Monk on Jul 12, 2013 at 05:01 UTC | |
by The_Dj (Beadle) on Jul 12, 2013 at 05:47 UTC | |
by hippo (Bishop) on Jul 12, 2013 at 09:13 UTC |
Back to
Seekers of Perl Wisdom