should be locked
... the expected behavior ...
Your understanding of file locking semantics on Linux is incorrect. From the reference link given, you are basing your assumption on Windows file semantics. They dont apply on most unix based systems.
I couldn't find a hugely authoritative source but wikipedia however it is trivial to test.
https://en.wikipedia.org/wiki/File_locking#In_Unix-like_systems
Unix-like operating systems (including Linux and Apple's OS X) do not normally automatically lock open files or running programs.
(Wikipedia is actually wrong about running programs, so I edited it!)
On Linux, its normal operation to allow multiple writers and readers to operate on the same file at the same time.
The only time this is not true is when the file itself is an executable object that is currently loaded and you request write access.
File Locking is done as a non-mandatory option and is done via fcntl
, flock
or lockf
which all the applications using the file must support and be using the same locking method for it to work.
Another method often employed is to create a new file which is a copy of the old file as a temporarily named file, then rename it over the top of the old file. This works as all renames are atomic on posix compatible filesystems -- people will see either the old file or the new file but not a mix of both.
If you want to achieve multiple writers editing the same file, you'll probably need to go with a method like git
so users can push the changes to a change repository.
Or alternatively just use a Windows system which does the locking you understand if this feature is that critical to you.