操作系统复习四

ch4 Deadlock
Deadlock:
A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.

–The system model for deadlocks first requires a process request a resource, then use the resource, and finally release the resource.

在这里插入图片描述


Basic Facts:
1.If graph contains a cycle -> no deadlock
2.If graph contains a cycle ->
if only one instance per resource type, then deadlock
if several instances per resource type, possibility of deadlock.


产生死锁的四个必要条件:
(1) 互斥条件:一个资源每次只能被一个进程使用。
(2) 请求和保持条件:一个进程因请求资源而阻塞时,对已获得的资源保持不放。
(3) 不可抢占条件:进程已获得的资源,在末使用完之前,不能强行剥夺,只能在进程使用完时由自己释放。
(4) 循环等待条件:若干进程之间形成一种头尾相接的循环等待资源关系。
这四个条件是死锁的必要条件,只要系统发生死锁,这些条件必然成立,而只要上述条件之一不满足,就不会发生死锁。
Deadlock Prevention:
Restrain the ways request can be made
1.Mutual Exclusion - not required for sharable
resources ; must hold for non-sharable resources
2. Hold ans Wait - must guarantee that whenever a process requests a resource , it does not hold any other resources


Resource Allocation Graph with a Deadlock:

在这里插入图片描述
Graph with a Cycle but No Deadlock
在这里插入图片描述


Avoidance Algorithms
1.Single instance of a resource type:
Use a resource-allocation graph
2.Multiple instances of a resource type:
Use the banker’s algorithm
在这里插入图片描述


Banker’s Algorithm:

Data Structures:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
Example of Banker’s Algorithm:
1.
在这里插入图片描述
Need = Max - Allocation
P0 7 4 3
P1 1 2 2
P2 6 0 0
P3 0 1 1
P4 4 3 1

safe state sequence is:
P1 -> P3 -> P4 -> P2 -> P0

在这里插入图片描述

2.
在这里插入图片描述

在这里插入图片描述
系统安全

3.在这里插入图片描述

在这里插入图片描述
(1)
在这里插入图片描述
(2)Safe.
(3)Yes.

在这里插入图片描述
在这里插入图片描述

(1)Safe State.
(2)No.


Question:
1.
在这里插入图片描述

Safe State.
Banker’s algorithm.
2.

在这里插入图片描述
在这里插入图片描述


Resource Preemption:
Selecting a victim - minimize cost
Rollback - return to some safe state, restart process for that state
Starvation - same process may always be picked as victim, including number of rollback in cost factor.

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值