Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concurrency issue while using cp 2

Status
Not open for further replies.

ddrillich

Technical User
Jun 11, 2003
546
0
0
US
Good Day,

It appeared this morning, when the beeper woke me up at 4:15 AM ;-) that while we ran the cp command on a tiny file, another process tried to read the file and didn't find the complete file - the SAX parser threw a 'Premature end of file' SAX exception.
Hours later, the SAX parser had no problem reading the same file.

So, my question is - is the cp operation an atomic one?

Regards,
Dan
 
mv is, cp isn't. you get what is there at the time. A small file should be nearly atomic, but there is no guarantee.
 
I think you already know the answer. :) No, it isn't. I'm presuming it was attempting to read the destination file?

If it needs to be atomic, copy to a temporary filename and then rename. Seems like overkill for a tiny file though, you were probably just very unlucky on that occasion.

Annihilannic.
 
egp, mv isn't atomic either if you are moving between filesystems.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top