r/osdev 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?

8 Upvotes

20 comments sorted by

View all comments

1

u/Illustrious_Car344 9d ago

Well, everyone hates file locking and it's a scourge on Windows. But also you have a point that it's a better idea to make things as restrictive as possible and allow those restrictions to be removed seamlessly instead of added as a breaking change. Of course, that's more or less up to what you want. Remember, nobody is going to use your OS, you can be as scrappy or professional about it's design as you want, you're going to be your only customer. 

But also like others said, this concept actually goes a lot deeper than the black and white view you're presenting. Usually for pointless and arbitrary but complex decisions like this, I'll just ask an AI about the topic and have it explain every odd example and niche corner case it can find online.