No Windows, por que você não pode sobrescrever o executável de um aplicativo em execução?

2

Nos sistemas Linux, isso não causa problemas: o exe é carregado no RAM quando é lançado. O arquivo pode então desaparecer, ser movido, etc. sem interação alguma.

Este não parece ser o caso no Windows. Existe uma razão para esse comportamento?

    
por Peltier 27.09.2013 / 18:06

1 resposta

7

De Bloqueio de Arquivos de Execução do StackOverflow: o Windows faz, o Linux não . Por quê? :

De Oren Shemesh 's answer :

Linux has a reference-count mechanism, so you can delete the file while it is executing, and it will continue to exist as long as some process (Which previously opened it) has an open handle for it. The directory entry for the file is removed when you delete it, so it cannot be opened any more, but processes already using this file can still use it. Once all processes using this file terminate, the file is deleted automatically.

Windows does not have this capability, so it is forced to lock the file until all processes executing from it have finished.

De resposta de Perry Lorier:

Linux does lock the files. If you try to overwrite a file that's executing you will get "ETXTBUSY" (Text file busy). You can however remove the file, and the kernel will delete the file when the last reference to it is removed. (If the machine wasn't cleanly shutdown, these files are the cause of the "Deleted inode had zero d-time" messages when the filesystem is checked, they weren't fully deleted, because a running process had a reference to them, and now they are.)

    
por 27.09.2013 / 18:40

Tags