Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I noticed when a file is executed on Windows (.exe or .dll)for installation, it is locked and cannot be modified, whereas Linux allows user to modify them by delete/edit.

Why does Windows lock when Linux does not? Is there an advantage to locking?

share|improve this question
Because the type of OS Windows is differnt then the type of OS Linux is. How they handle a file is entirely different. – Ramhound Mar 4 '14 at 13:13
@Ramhound i understand the type of os is differnt,but my question is why there is a diffrence,may i know why downvote – BlueBerry - Vignesh4303 Mar 4 '14 at 13:16
The downvote is because "Why" questions are horrible Superuser questions. As for there they are different. Microsoft want the NT kernel to be different. Additionally Windows used to be a shell over DOS – Ramhound Mar 4 '14 at 13:28
Raymond Chen wrote an article on why microsoft chose to not allow overwriting of files (specifically dlls):… – Kryten Mar 4 '14 at 15:39
up vote 6 down vote accepted

Both operating systems lock the file data. Any attempt to modify an executable while it is running or a library while it is mapped will produce a "text file busy" error on Linux.

$ gcc foo.c -o f
$ ./f &
[1] 2017
$ ls > f
bash: f: Text file busy

The difference is only in what is locked. Windows locks the directory entry, Linux locks the file data. This difference exists for historical reasons -- a long time ago, Windows treated directory entries and file data as essentially equivalent and, to retain compatibility, many of the consequences of that design have been retained. Linux has always treated directory entries as a pointer to file data.

share|improve this answer
From a windows user POV: Linux just hides the file from the user when you click delete. The data is still there and uses space on the drive. Only when the executable terminates, the file (/file data) gets deleted. – DasKrümelmonster Mar 4 '14 at 13:45
@DasKrümelmonster Yep. What people think of as "delete" is actually just an unlink on Linux, removing the directory entry which "links" the file data to the parent directory. If that's the file data's last reference, it is freed. If not, not. So you can remove, rename, or even replace a directory entry with no changes to the file data is referred to. You can also have two directory entries that refer to the very same file data. And you can have file data with no directory entry (while it's open, at least). – David Schwartz Mar 4 '14 at 13:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .