There are several processes in the operating system that execute concurrently, they continuously request, use, release system resources, although the system's process coordination, communication mechanism will control them, but there may be several processes are waiting for each other to release resources to continue to run, otherwise blocking the situation. At this point, if no external factors, who can not release resources, no one can unblock the state. In this case, the deadlock in the operating system is defined as two or more processes in the system waiting indefinitely for conditions that will never occur, the system is in a state of stagnation, and this is the deadlock.
Deadlocks are caused mainly by:
(1) Because of insufficient system resources.
(2) The sequence of the process of moving forward is unsuitable.
(3) Improper allocation of resources.
If the system has sufficient resources, the process's resource requests can be met, the likelihood of deadlock is very low, otherwise, because of the contention for limited resources and fall into deadlock.
Second, the process is running in a different order than the speed, may also produce deadlock.
Four necessary conditions to produce a deadlock:
(1) Mutually exclusive condition: A resource can only be used by one process at a time.
(2) Request and retention conditions: a process that is blocked by requesting resources, retains the resources that have been acquired.
(3) Non-deprivation of conditions: the resources that the process has acquired cannot be forcibly deprived until the end of use.
(4) Cyclic waiting condition: the process of forming a kind of end-to-end circular waiting resource relationship between several processes.
The main strategies for dealing with deadlocks are:
(1) Deadlock prevention: Destroys any one of the required deadlock conditions to prevent deadlocks. For example, when a user requests a resource to request a one-time request for all the resources required, which destroys the retention and waiting conditions, the resource is layered to get to the next level of resources before it can request a layer of resources, it destroys the loop wait condition. Prevention usually lowers the efficiency of the system.
(2) Deadlock avoidance: avoidance means that the process determines whether these operations are safe each time the resource is requested, for example, by using the banker algorithm. The execution of the deadlock avoidance algorithm increases the overhead of the system.
(3) Deadlock detection: Deadlock prevention and avoidance are prior measures, and deadlock detection is to determine whether the system is in a deadlock state, if it is, the implementation of the deadlock cancellation strategy.
(4) Deadlock cancellation: This is used in conjunction with deadlock detection, the way it is used is deprivation. The resources owned by a process are forcibly retracted and assigned to other processes.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/unix/