请输入您要查询的百科知识:

 

词条 文件锁
释义

File locking is a mechanism that enforces access to a computer file by only one user or process at any specific time. The purpose of locking is to prevent the classic interceding update scenario.

The interceding update problem may be illustrated as in the following example:

1. Process A reads a customer record from a file containing account information, including the customer's account balance and phone number.

2. Process B now reads the same record from the same file so it has its own copy.

3. Process A changes the account balance in its copy of the customer record and writes the record back to the file.

4. Process B--which still has the original stale value for the account balance in its copy of the customer record--updates the customer's phone number and writes the customer record back to the file.

5. Process B has now written its stale account balance value to the file, causing the changes made by process A to be lost.

File locking prevents this problem by enforcing the serialization of update processes to any given file. Most operating systems support the concept of record locking which means that individual records within any given file may be locked, so increasing the number of concurrent update processes.

One use of file locking is in database maintenance where it can serialize access to the entire physical file underlying a database. While this prevents any other process from accessing the file it can actually be more efficient than individually locking a large number of regions in the file by removing the overhead of achieving and releasing each lock.

中文翻译:

文件锁定是一种机制,强制访问计算机文件只能由一个用户或在任何特定时间的过程。锁定的目的是要防止的恶意更新场景。调解更新的问题可能是在下面的例子所示:

1。一个进程读取从一个文件包含帐户信息,包括客户的帐户余额和电话号码的客户记录。

2。进程B读取相同的文件相同的记录,所以它有它自己的拷贝。

3。进程A在其客户记录副本的帐户余额的变化,并记录写回文件。

4。进程B - 仍然有原始陈旧的价值在其客户记录副本的帐户余额 - 更新客户的电话号码,并写入客户记录文件。

5。进程B现在已经写入了其过时的帐户平衡值的文件,造成到丢失的过程中所作的更改。

文件锁定防止这个问题,任何给定的文件执行更新过程的系列化。大多数的操作系统都支持这意味着,在任何给定的的文件的个人记录可能会被锁定,所以越来越多的并发更新过程的记录锁定的概念。在数据库维护的文件锁定的用途之一是它可以序列化到整个底层数据库的物理文件的访问。虽然这可以防止任何其他进程访问文件,它实际上可以被删除每个锁的实现和释放开销比单独锁定一个文件中的地区大量更有效率。

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/2/6 12:51:39