On Tue, 11 Jun 2002, Sam Tregar wrote:

> On Mon, 10 Jun 2002, Tom Brown wrote:
> 
> > ?? AFAIK, Files opened in append mode, and written to without buffering,
> > should _not_ get corrupted in any manner that flock would prevent.
> > (basically small writes should be atomic.)
> 
> Right, and does Perl write with buffering when you call print()?  Yes, it
> does!

huh? That's what $| is all about, and $|++ is a pretty common line of
code.

> 
> > that should be pretty universal for most UNIXs
> 
> I've actually never heard this before.  I've been taught that if you have
> multiple processes writing to one file you must use flock() or another
> equivalent mechanism to prevent overwrites.  Do you have a source where I
> could learn about guaranteed atomic file writes without locking under
> UNIX?

man(2) open.  see the O_APPEND option... the only footnote is that it
doesn't work properly via NFS...

This doesn't cover why small writes are atomic though. And man(2) write
doesn't seem to either, but the open man page on my system says

       O_APPEND
               The  file is opened in append mode. Initially, and
               before each write, the file pointer is  positioned
               at  the  end  of  the  file,  as  if  with  lseek.
               O_APPEND may lead to corrupted files on  NFS  file
               systems if more than one process appends data to a
               file at once.  This is because NFS does  not  sup<AD>
               port appending to a file, so the client kernel has
               to simulate it, which can't be done without a race
               condition.

which certainly implies that you can expect local files _not_ to get
corrupted.

p.s. I'm not the only one who considers it impolite to have off-list
messages taken back onto the list... I generally don't post AFAIK comments
to lists, prefering to keep the signal to noise ratio higher.


> 
> -sam
> 
> 
> 

----------------------------------------------------------------------
[EMAIL PROTECTED]   | Courage is doing what you're afraid to do.
http://BareMetal.com/  | There can be no courage unless you're scared.
                       | - Eddie Rickenbacker 



Reply via email to