Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: File lock demo

by LanX (Sage)
on Apr 21, 2021 at 19:44 UTC ( #11131543=note: print w/replies, xml ) Need Help??


in reply to Re: File lock demo
in thread File lock demo

Thanks, very informative!!! :)

In my case I'm indeed logging the PID, but as a name of another file plus timestamp. And I'm indeed writing content into that other file.

My issue is that Windows (or maybe the way flock is ported to Win) doesn't allow me to read a file which is "partially locked" by Perl. (at least I couldn't figure out how)

Hence the content is only readable if no script is running.

This is most probably different on Linux but caused me much headache to debug and led me to the shown solution with an empty lock-file.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^3: File lock demo
by davido (Cardinal) on Apr 21, 2021 at 20:35 UTC

    Empty lock files certainly aren't wrong either. MJD's talk discusses how many problems can be solved by using a lockfile that is different from the target working files. And that's what you're doing. I mostly just didn't want someone seeing open my $fh, '>', ...; and then flock, and think this idiom will translate well to locking an output file that they intend to write to.


    Dave

      > and think this idiom will translate well to locking an output file that they intend to write to.

      Yeah, I have to make that clear to my colleagues. My concern was the warning in the docs that locking might fail if the lock-file is not opened for writing.

      And the side effects on Win are giving me a hard time when following recipes born on Linux.

      Thanks for sharing those links! :)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11131543]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2022-08-13 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?