What will happen if two process access the same file without a lock?

file, linux

Solution

1, 2. The read and write requests are essentially broken into smaller requests and these are performed in no particular order. The result is a complete jumble up. There are some exceptions to this, such as several processes appending to a file. In this case each write is atomic.

4, 6. File removal has no effect on file handles that are already open.

3,5. Same as either 1,2 or 4,6, depending on whether it's a copy or a move (== delete the target and rename the source).

Problem

In linux: if two process access the same file without any lock, what will happen? Considering the following cases: - Process A is reading a file while process B is writing it. - Both process A and process B are writing the same file. - Process A is reading a file, process B is copying/moving another file to replace the original file - Process A is reading a file, process B is removing the file - Process A is writing a file, while process B is copying/moving another file to replace the original file - Process A is writing a file, process B is removing the file

Original source