Two processes opening the same file for writing Two processes opening the same file for writing windows windows

Two processes opening the same file for writing


There's nothing particularly exciting about two processes opening the same file for writing.

The fun part starts when those processes try to both write to the same file. The OS is not going to play a referee. Each individual process is going to get scheduled by the OS to execute when the OS feels like it. Whatever the process does during its time slice, the OS will generally stay out of its way. One process may write something to the file, then the other process might write something, or might not. Depending on what the code does.

So, unless explicit steps are taken, in some way, for multiple processes to coordinate their access to the file, the end result of multiple processes writing to a file cannot be predicted. The computer is not going to catch fire or implode, the world will not come to an end. But, every time this experiment gets repeated, the results will be different.