Mandatory File Locks vs. Advisory File Locks in OSs


One of the most visible features of an operating system is the file system where it provides the mechanism for the file storage, and access to both programs and data. With such capabilities of the computing systems, to store information on different storage media such as magnetic disks, optical disks, magnetic tapes; operating systems have a big role in providing a uniform logical view of such information storage within the computing systems    to enable users to handle all the files operations. Some of the operations that can be handled by the operating system are: Creating a file, Reading a file, Writing a file, and deleting a file. Other common operations include appending new information to the end of an existing file, and renaming an existing file. With such operations implemented by most of the operating system, some of these operations can be combined to perform other file operation (Silberschatz and Galvin, 2009).  

A file defines a logical storage unit that represents an abstract of the physical properties of its storage devices. A file is a collocation of related information that has its name and is recorded on secondary storage (the disk); it’s the smallest element of the logical storage and such information cannot be written to a disk unless they are within a file. Files are mapped by the operating system into its physical devices. To provide content persistence during power failures or system reboots; storage devises are used via the computing system to provide such features. With such files exist on the storage device and handled by the operating system; a locking mechanism is required to handle the file sharing among processes. The operating system facilitates different locking mechanism to allow one process to lock a file and prevent other processes from gaining access to such file. Such mechanism maintains the shared files among several processes (Harnett, n.d.).

It’s imperative that the operating system provide the mechanism that allows the shared access to file by different processes concurrently. With such requirements, most of the operating system provides the shared lock mechanism (also called the reader lock) where several processes can acquire the lock concurrently on the file. Another mechanism provided by the operating system called the exclusive lock (also called write lock) where only one process can acquire such a lock at a time (Milenkovic, 1987).   

Mandatory Locks vs. Advisory Locks

Galli (1999) explained that operating systems provide either mandatory file-locking mechanism or advisory file-locking mechanism. With the mandatory file-locking mechanism implemented, once a process acquires an exclusive lock, the operating system will prevent any other process from access the locked file. With such mechanism in place, the operating system will prevent access to the locked file until the exclusive lock is released. Also, with mandatory locking some measures is required to ensure that processes do not become involved in a deadlock while trying to acquire file locks. On the other hand, an advisory mechanism provided by the operating system allows processes to find the status of locks and decide what to do. With such mechanism it is up to the process to ensure that the file lock is appropriately acquired and released.

With mandatory locking in place, it suspends a process requesting a locked file until the file is free. Concurrent writes to a single file is not desirable by most of the operating systems, and to prevent such scenario from happening, lock mechanism is used to provide the level of integrity required in the file system. Such mechanism guarantees that only one process can write to a file at a time. Traditional operating systems usually lock the entire file, while modern operating systems support the locking of a range of bytes within a file. Such technique provide users with more flexible environment where sharing a locked file might be possible. If the concurrent lock requested it’s usually done on different block of bytes within the same file. On the other hand when advisory lock is implemented within the file system, locking condition on the file that is requested by a process returns a result indicating whether the lock was obtained or not; and as such; the process can ignore the result and proceed with the I/O or waits for the file to be free, and apply the lock. Such technique gives users more flexibility to share the file access in a lock mode. File systems can’t use both advisory and mandatory file locking on the file at the same time. During the file open process, the mode of such file will determines whether locks on a file can be treated as advisory or mandatory (Silberschatz and Galvin, 2009).

File Locking and User Discretion

Silberschatz and Galvin (2009) explained that when a programs declare the desire of using a file by a process with file locking mode, two possible forms of file locking usually implemented by the file system to respond to such request: Read and Write. It is always preferred to use the shared mode of locking (called advisory locking) where the file is in shared mode and programs can have the choice to wait until the file is free to claim exclusive use of the file or declares another share lock to the file. Such technique provides more flexible environment especially in a multi-user environment and also promotes the multiprogramming environment that can speed up the computing system performance.


Silberschatz and Galvin (2009) explained that file systems are important part of the operating system. There are two parts of any file system: the mechanism for storing files and the directory structure where these files will be organized. In modern operating systems where it is possible for users of such operating systems to access the same file concurrently, it becomes necessary to implement a mechanism to maintain access control on such file and also implement different forms of file protection. File systems are implemented within the operating systems to handle files manipulation such as opening, creating, editing, and deleting a file.

Milenkovic (1987) explained that attention must be paid when sharing files between users and/or processes. Such scenario can happen in multi-user environment and also in a single user environment where there may be more than one process running simultaneously and requesting access to such file. Inconsistencies in the data can occur if one process tries to read information from a file while another process is modifying the same file. Operating systems avoid such problem by controlling the shared access of the files within any computing system.

With mandatory lock (file locking mechanism), when a program asks the operating system to access a file, the request can be granted only if the file is not in use. If the file is open, the program must wait until such file is free. While the file mandatory locking technique is easy to implement, it suffers from the disadvantage of having the entire file unavailable to other users/programs and becomes required for other programs to wait for certain time until the file is free. On the other hand with advisory lock (shared lock), processes can still read and write from a file while such file is locked, since there is away for a process to check for the existence of lock before a read or write action (Stallings, 1991). 


Dhamdhere, D. (2006) Operating Systems: A concept-based Approach. 2nd ed.London: McGraw Hill Higher Education.

Harnett, S. (n.d.) How an operating system’s file system works [Online]. Available from: (Accessed: 04 September 2010).

Galli, D. (1999) Distributed Operating Systems: Concepts and Practice. 1st ed. NY:Prentice Hall.

Milenkovic, M. (1987) Operating Systems: Concepts and Design. 1st ed.London: McGraw Hill Higher Education.

Silberschatz, A. & Galvin, P. (2009) Operating System Concepts. 8th ed. NJ: John Wiley & Sons, Inc.

Stallings, W. (1991) Operating Systems: Concepts and Examples. 2nd ed.USA:Macmillan.



1 Comment »

  1. 1
    jhansi Says:

    thank u

RSS Feed for this entry

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: