For faster navigation, this Iframe is preloading the Wikiwand page for
文件锁定.
文件锁定是一种在特定时间只允许一个用户或进程拥有对特定计算机文件的访问权限的机制。[1]计算机系统实现该特性以避免竞争读写。以下是竞争写的一个例子:
- 进程A从一个包含顾客账户信息(包括其账户结余和电话号码)的文件中读取一条记录。
- 进程B从同一个文件中读取同一条记录并有一份自己的拷贝。
- 进程A在它的那份记录中修改账户结余并将记录写回文件。
- 进程B自己的记录中仍然包含原有的账户结余数据,它在自己的记录中也修改了它并写回文件。
- 进程B的写回操作导致进程A的更改丢失。
绝大多数操作系统支持记录锁定的概念,也就是任何文件中单个记录可以被锁定,从而增加并发更新进程的数量。数据库维护需要锁定文件,从而它有权访问数据库的整个物理文件。虽然这确实阻止其他进程访问此文件,但减少每个锁的经常性开销比整体锁定文件中很大数量的区域更高效。
文件锁定的不合理用法可能产生差的性能或死锁。文件锁定可能也指用户使用如Windows安全、NTFS访问权限或第三方的文件锁定软件提供文件额外安全性的过程。
Microsoft Windows
Microsoft Windows使用三种不同的机制管理对共享文件的访问:
- 应用程序对整个文件的共享访问方式,包括读、写、删除。[2]
- 对单个文件的字节范围锁定[3]
- Windows文件系统不允许执行已经按照写或删除方式打开的文件
Windows继承了MS-DOS 3.3引入的文件共享访问控制。如果打开文件时不指定共享访问方式,缺省禁止其他进程按照读、写、删除来打开该文件(但读取文件属性是允许的)。
操作系统默认锁定正在运行的可执行程序,阻止其他程序修改或删除它。但允许改名、复制。
参考文献
- ^ Linux数据管理——文件锁定. 2013-08-29 [2016-09-29]. (原始内容存档于2019-12-07) (中文).
这是文件的一种安全的更新方式,当一个程序正在对文件进行写操作时,文件就会进入一种暂时状态,在这个状态下,如果另一个程序尝试读这个文件,它就会自动停下来等待这个状态结束
- ^ windows-sdk-content. CreateFileW function. docs.microsoft.com. [2018-11-07]. (原始内容存档于2019-04-19) (美国英语).
- ^ windows-sdk-content. LockFileEx function. docs.microsoft.com. [2018-11-07]. (原始内容存档于2019-06-21) (美国英语).
{{bottomLinkPreText}}
{{bottomLinkText}}
This page is based on a Wikipedia article written by
contributors (read/edit).
Text is available under the
CC BY-SA 4.0 license; additional terms may apply.
Images, videos and audio are available under their respective licenses.
{{current.index+1}} of {{items.length}}
Thanks for reporting this video!
This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:
An extension you use may be preventing Wikiwand articles from loading properly.
If you're using HTTPS Everywhere or you're unable to access any article on Wikiwand, please consider switching to HTTPS (https://www.wikiwand.com).
An extension you use may be preventing Wikiwand articles from loading properly.
If you are using an Ad-Blocker, it might have mistakenly blocked our content.
You will need to temporarily disable your Ad-blocker to view this page.
✕
This article was just edited, click to reload
Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}
Follow Us
Don't forget to rate us
Oh no, there's been an error
Please help us solve this error by emailing us at
support@wikiwand.com
Let us know what you've done that caused this error, what browser you're using, and whether you have any special extensions/add-ons installed.
Thank you!