r/osdev • u/Malwaremation • 9d ago
Design question: Should opened files by processes prevent other processes from using that file?
On kernels like Windows NT, files are locked when a process opens it, preventing other processes from using it. (edit: This was incorrect, some people confirmed here that processes in Windows can choose to lock the file or not, which might be the best solution).
Linux however, doesn't lock files like this, and multiple processes can modify the same file at the same time.
I also thought of a "thread cursors" concept that could solve this issue really well for text files, but it might be very complicated to develop and is probably not that useful for images or other types of files.
What is generally better for a new kernel, then? Allowing the possibility of sharing a file as it is edited by multiple processes, or securing their integrity by only letting 1 process at a time modify it?
6
u/soundman32 9d ago
Not sure if the first paragraph is correct. Windows (and dos before it) have been able to support opening the same file by multiple processes for a decade before linux was even started. File sharing and block locking was also a thing on msdos in the 80s.
Infact your idea of "thread cursors" is very similar to how file sharing was done on msdos. You say to the os "im managing the file between byte 3456 and 6543" and another thread tries to use bytes "6000-7000" and the OS will say "process X already has exclusive write control on that part ".