As I only plan to read the file - does this indicate I do not need to lock it? It is a static file and will theoretically not be changed ever. Should I use shared locks or are these rendered unnecessary by the fact I never plan to write or append to the file?
If your scripts (or any other programs) don't modify the files you don't need to lock them.

The only reason to (shared-)lock files you are reading is when both:

  1. Someone might be updating the file, and that someone is doing an exclusive lock himself.
  2. Things go wrong when the file you are reading is malformed, for any definition of 'wrong' and 'malformed'.
For instance: say I have a small script which shows the last X lines of a log-file. Now, I only use the script for debugging purposes, so even though the log-file might be updated, I do not need to lock the file because it doesn't matter if the read goes wrong sometimes (in this case the most likely 'misread' will be an incomplete line at the end).

On the other hand, if I use a file for passing data from one program to the other, I really need the data to be consistant, so I should use locking on the read and the writing side.

Hope this clears it up a bit ;-)

-- Joost downtime n. The period during which a system is error-free and immune from user input.

In reply to Re: The necessity of flock-ing files that are only to be read. by Joost
in thread The necessity of flock-ing files that are only to be read. by Nemp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.