Processing strategy of deadlock detection and de

1. The process deadlock

Here Insert Picture Description

If neither take measures to prevent deadlock, do not take measures to avoid deadlock, the system is likely to deadlock. In this case, the system should provide two algorithms:
① deadlock detection algorithms: the state of the system for detecting, to determine whether the system is deadlocked.
② lift the deadlock algorithm: When the system finds a deadlock has occurred, using this algorithm system can be freed from the deadlock state.

2. Deadlock detection

In order to detect whether the system has a deadlock occurs, must:
① with certain data structures request and save the resource allocation information:
② to provide an algorithm to detect whether the system has entered a deadlock state by using the above information.

Here Insert Picture Description

Here Insert Picture Description

If the remaining number of available resources are sufficient to meet the needs of the process, then this process is not being blocked, can be successfully implemented. If this process is over the implementation of restitution system resources, we can make is activated and successfully execute down some processes are waiting for resources. After Accordingly, these processes are activated will perform over the return of some resources, which could in turn activate the process some other obstruction.

If the analysis according to the above process, and ultimately eliminate all sides , this figure is said to be completely simplified . At this point certainly no deadlock occurs (equivalent to find a safe sequence)

If the final can not eliminate all sides, then the time is a deadlock occurred.
Those final process is still attached to the side of a deadlock in the process of state.

Here Insert Picture Description

Deadlock detection algorithm:

1)在资源分配图中,找出既不阻塞又不是孤点的进程Pi (即找出一条有向边与它相连,且该有向边对应资源的申请数量小于等于系统中已有空闲资源数量。如下图中,R1没有空闲资源,R2有一个空闲资源。若所有的连接该进程的边均满足上述条件,则这个进程能继续运行直至完成,然后释放它所占有的所有资源)。消去它所有的请求边和分配变,使之称为孤立的结点。在下图中,P1是满足这一条件的进程结点,于是将P1的所有边消去。

2)进程Pi所释放的资源,可以唤醒某些因等待这些资源而阻塞的进程,原来的阻塞进程可能变为非阻塞进程。在下图中,P2 就满足这样的条件。根据1)中的方法进行一系列简化后,若能消去图中所有的边,则称该图是可完全简化的。

Here Insert Picture Description

死锁定理:如果某时刻系统的资源分配图是不可完全简化的,那么此时系统死锁

3. 死锁的解除

一旦检测出死锁的发生,就应该立即解除死锁。

补充:并不是系统中所有的进程都是死锁状态,用死锁检测算法化简资源分配图后,还连着边的那些进程就是死锁进程

解除死锁的主要方法有:
1.资源剥夺法。挂起(新时放到外存上)某些死锁进程,并抢占它的资源,将这些资源分配给其他的死锁进程。但是应防止被挂起的进程长时间得不到资源而饥饿。
2.撤销进程法(或称终止进程法)。强制撤销部分、甚至全部死锁进程,并剥夺这些进程的资源.这种方式的优点是实现简单,但所付出的代价可能会很大。因为有些进程可能已经运行了很长时间,已经接近结束了,一 旦被终止可谓功亏一篑,以后还得从头再来。
3.进程回退法。让一个或多个死锁进程回退到足以避免死锁的地步。这就要求系统要记录进程的历史信息,设置还原点。

How to decide "who is on hands-on"
1. Process Priority
2. How long have been performed
3. How long can finish
4. How much resources have been used for the process
5. The process is interactive or batch-type

Here Insert Picture Description

4. Summary

Here Insert Picture Description

Published 168 original articles · won praise 1 · views 2965

Guess you like

Origin blog.csdn.net/yrx420909/article/details/104461351