In a multiprocessing environment, several processes compete for limited resources. A running process goes to waiting state when a resource is not available. The process could not change its state because some other process holds the resources. This is called a deadlock.
Normal Conditions
The operating system does not provide with deadlock prevention mechanism, the programmers must write deadlock-free programs.
Under normal circumstances a process utilizes resources in the following way:
- The process request for the resource, and must wait if the resource is not granted immediately.
- The process once allocated the resource, can operate on it.
- The process must release the resources once finished execution.
The list of system calls used to manage resources via system calls are:
- request ()
- release ()
- open ()
- close ()
- allocate ()
- free ()
- wait ()
- signal ()
Necessary Conditions for Deadlock
A deadlock happens if four of the following condition hold simultaneously in a system:
- Mutual exclusion
- Hold and Wait
- No Preemption
- Circular wait
Mutual Exclusion
Only one process can use the resource at a time. The process must not share the resource with another process. If the resource is requested by another process then it has to wait until the resource is released.
Hold and Wait
A process must be holding at least one resource and waiting for additional resources that are held by other processes.
No Preemption
The resources held by the process cannot be preempted and it can only be released by that process after completing its tasks.
Circular Wait
A set circular wait
, and also known as hold-and-wait
.
References
- Abraham Silberschatz, Peter B. Galvin, Greg Gagne (July 29, 2008) Operating System Concepts, 8 edn., : Wiley.
- Tanenbaum, Andrew S. (March 3, 2001) Modern Operating Systems, 2nd edn., : Prentice Hall.