File Locking

Care must be taken when sharing files between users and/or process. Even on a single user system there may be more than one process running simultaneously. If one process tries to read information from a file at the same time as another process is modifying it this could cause inconsistencies in the data.

To avoid this problem, the file system controls access to shared files. When a program asks the operating system for access to a file, this is only granted if the file is not already in use. If the file is already open, the program must wait until it is free.  This is known as file locking, and is supported by most operating systems including MS-DOS and Windows.

File locking is simple to implement, but suffers from the disadvantage that the entire file is unavailable to other programs for an indeterminate amount of time. In the case of a major file, such as a corporate database, many different programs or users may require access at the same time.

Fortunately, these different users or programs only likely to want access to one relatively small part of the file at a time, and these will probably be different parts, so we could split the file up into sections, or records, and lock each section separately. Once a program has finished using a section it is unlocked and available for use by other programs.

This type of access control is known as record locking or block locking. It is supported by UNIX/Linux, MS-DOS and Windows, although programs must be specially written to take advantage of it, otherwise file locking will be used.

Next: Logical Structure