title: Safe to have multiple processes writing to the same file at the same time? [CentOs 6, ext4]
body: <p>I'm building a system where multiple slave processes are communicating via unix domain sockets, and they are writing to the <strong>same file</strong> at the same time.  I have never studied filesystems or this specific filesystem (ext4), but it feels like there might be some danger here.</p>
  
  <p>Each process writes to a disjoint subset of the output file (ie, there is no overlap in the blocks being written).   For example, <code>P1</code> writes to only the first 50% of the file and <code>P2</code> writes only to the second 50%.  Or perhaps <code>P1</code> writes only the odd-numbered blocks while <code>P2</code> writes the even-numbered blocks.</p>
  
  <p>Is it safe to have <code>P1</code> and <code>P2</code> (running simultaneously on separate threads) writing to the same file without using any locking?  In other words, does the filesystem impose some kind of locking implicitly?</p>
  
  <p><strong>Note:</strong> I'm unfortunately not at liberty to output multiple files and join them later.</p>
  
  <p><strong>Note:</strong> My reading since posting this question does not agree with the only posted answer below.  Everything I've read suggests that what I want to do is fine, whereas the respondent below insists what I am doing is unsafe, but I am unable to discern the described danger.</p>