For faster navigation, this Iframe is preloading the Wikiwand page for 文件锁定.

文件锁定

本条目存在以下问题,请协助改善本条目或在讨论页针对议题发表看法。 此条目可参照英语维基百科相应条目来扩充。 (2016年9月29日)若您熟悉来源语言和主题,请协助参考外语维基百科扩充条目。请勿直接提交机械翻译,也不要翻译不可靠、低品质内容。依版权协议,译文需在编辑摘要注明来源,或于讨论页顶部标记((Translated page))标签。 此条目过于依赖第一手来源。请补充第二手及第三手来源,以改善这篇条目

文件锁定是一种在特定时间只允许一个用户或进程拥有对特定计算机文件的访问权限的机制。[1]计算机系统实现该特性以避免竞争读写。以下是竞争写的一个例子:

  1. 进程A从一个包含顾客账户信息(包括其账户结余和电话号码)的文件中读取一条记录。
  2. 进程B从同一个文件中读取同一条记录并有一份自己的拷贝。
  3. 进程A在它的那份记录中修改账户结余并将记录写回文件。
  4. 进程B自己的记录中仍然包含原有的账户结余数据,它在自己的记录中也修改了它并写回文件。
  5. 进程B的写回操作导致进程A的更改丢失。

绝大多数操作系统支持记录锁定英语record locking的概念,也就是任何文件中单个记录可以被锁定,从而增加并发更新进程的数量。数据库维护需要锁定文件,从而它有权访问数据库的整个物理文件。虽然这确实阻止其他进程访问此文件,但减少每个锁的经常性开销比整体锁定文件中很大数量的区域更高效。

文件锁定的不合理用法可能产生差的性能或死锁。文件锁定可能也指用户使用如Windows安全、NTFS访问权限或第三方的文件锁定软件提供文件额外安全性的过程。

Microsoft Windows

Microsoft Windows使用三种不同的机制管理对共享文件的访问:

  1. 应用程序对整个文件的共享访问方式,包括读、写、删除。[2]
  2. 对单个文件的字节范围锁定[3]
  3. Windows文件系统不允许执行已经按照写或删除方式打开的文件

Windows继承了MS-DOS 3.3引入的文件共享访问控制。如果打开文件时不指定共享访问方式,缺省禁止其他进程按照读、写、删除来打开该文件(但读取文件属性是允许的)。

操作系统默认锁定正在运行的可执行程序,阻止其他程序修改或删除它。但允许改名、复制。


参考文献

  1. ^ Linux数据管理——文件锁定. 2013-08-29 [2016-09-29]. (原始内容存档于2019-12-07) (中文). 这是文件的一种安全的更新方式,当一个程序正在对文件进行写操作时,文件就会进入一种暂时状态,在这个状态下,如果另一个程序尝试读这个文件,它就会自动停下来等待这个状态结束 
  2. ^ windows-sdk-content. CreateFileW function. docs.microsoft.com. [2018-11-07]. (原始内容存档于2019-04-19) (美国英语). 
  3. ^ windows-sdk-content. LockFileEx function. docs.microsoft.com. [2018-11-07]. (原始内容存档于2019-06-21) (美国英语). 
{{bottomLinkPreText}} {{bottomLinkText}}
文件锁定
Listen to this article

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:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

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}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?