AM,
Well it kinda depends. A "write" is atomic in Unix so if
you're appending a chunk of data with only one underlying
write (as in a singular print, printf, or write)
you'll be okay (that is, that chunk of data will be appended as one piece of data to the file).
There are several reasons you may need locking:
- If you're spreading your
output across several writes and you want those several
to stay "clumped" in the file
- There's going to be some type of "read" dependency
where you're reading and writing at the same time and you want to block out writers while reading.
Other than that, append to your hearts content without
worrying about "losing" something (you won't).
-derby
update: Just one caveat, if the file you're appending
to is on an nfs partition, you do want locking for appending.
(Common sensical enough, the standard kernel can only control its own writes, not those of other processors).
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.