ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > ZSTU class(2019-2020-1) > homework >
homework-5 Version 0
👤 Author: by writer 2019-10-10 04:59:00
describe your understadings about Banker's Algorithm, and give your own demo example.

Please login to reply. Login

zhangleilaogeqqcom • 2019-10-17 23:23:43
1.

银行家算法是一种起初为银行设计的算法,用于避免银行在发放贷款时,不会发生不能满足所有客户需求的情况。在操作系统中银行家算法用来避免死锁。

银行家算法主要设置四个数据结构,分别用来描述系统中可利用的资源、所有进程对资源的最大需求、系统的资源分配,以及所有程序还需要多少资源。
<ol>
<li>可利用资源向量(Available):系统还可以分配的资源</li>
<li>最大需求矩阵(Max):进程的最大资源需要</li>
<li>分配矩阵(Alloction):进程已经获得的资源</li>
<li>需求矩阵(Need):进程还需要获得的资源</li>
</ol>
银行家算法的具体步骤如下:

假设 P1 进程提出请求 K 个资源

如果 K &lt;= Need,就继续步骤;否则出错,因为请求资源 K 不能超过还需要获得的资源

如果 K &lt;= Available,就继续步骤;否则出错,因为请求资源 K 不能超过系统还可以分配的资源 Available

系统试探分配资源,并修改下列数据
Available = Available - K;表示分配给 P1 K 个资源后,还剩多少系统可分配资源
Allocation = Allocation + K;表示 P1 已经获得的资源
Need = Need - K;表示进程 P1 还需要获得的资源

此时系统执行安全性算法,计算进程是否处于安全性状态
以下为银行家算法的例子:

<img src="https://img-blog.csdn.net/2018100410464656?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM0OTAyNDM3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" alt="在这里插入图片描述" />

<img src="https://img-blog.csdn.net/20181004105535672?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM0OTAyNDM3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" alt="在这里插入图片描述" /> PostVer 0

Please login to reply. Login

1989812974qqcom • 2019-11-07 12:38:51
When a process applies for the use of resources, the banker algorithm first tries to allocate resources to the process, and then judges whether the allocated system is in a safe state through the security algorithm. If it is not safe, the banker algorithm tries to invalidate the allocation and let the process continue to wait. PostVer 0

Please login to reply. Login

Reversion History

Loading...
No reversions found.