死锁 预防死锁避免死锁

僵局 (Deadlock)

In the multiprogramming operating system, there are a number of processing which fights for a finite number of resources and sometimes waiting process never gets a chance to change its state because the resources for which it is waiting are held by another waiting process. A set of a process is called deadlock when they are waiting for the happening of an event which is called by some another event in the same set.

在多程序操作系统中,存在许多争夺有限数量资源的处理,并且有时等待进程永远没有机会更改其状态,因为它等待的资源由另一个等待进程持有。 当一组进程等待同一组中另一个事件调用的事件发生时,它们称为死锁。

Here every process will follow the system model which means the process requests a resource if not allocated then wait otherwise it allocated will use the resources and release it after use.

在这里,每个进程都将遵循系统模型,这意味着该进程将请求资源(如果未分配),然后等待,否则分配的资源将使用该资源,并在使用后释放资源。

处理死锁的方法 (Methods for handling deadlock)

There are mainly four methods for handling deadlock.

主要有四种处理死锁的方法。

1.死锁无知 (1. Deadlock ignorance)

It is the most popular method and it acts as if no deadlock and the user will restart. As handling deadlock is expensive to be called of a lot of codes need to be altered which will decrease the performance so for less critical jobs deadlock are ignored. Ostrich algorithm is used in deadlock Ignorance. Used in windows, Linux etc.

这是最流行的方法,它的作用就像没有死锁,用户将重新启动。 由于处理死锁非常昂贵,因此需要更改许多代码,这将降低性能,因此对于不太关键的作业,死锁将被忽略。 鸵鸟算法用于死锁无知。 用于Windows,Linux等。

2.防止死锁 (2. Deadlock prevention)

It means that we design such a system where there is no chance of having a deadlock.

这意味着我们设计的系统不会出现死锁。

  • Mutual exclusion:

    互斥:

    It can’t be resolved as it is the hardware property. For example, the printer cannot be simultaneously shared by several processes. This is very difficult because some resources are not sharable.

    由于它是硬件属性,因此无法解决。 例如,打印机不能被多个进程同时共享。 这是非常困难的,因为某些资源不可共享。

  • Hold and wait:

    保持并等待:

    Hold and wait can be resolved using the conservative approach where a process can start it and only if it has acquired all the resources.

    保持等待可以使用保守的方法解决,在该方法中,只有当进程已获取所有资源时,进程才能启动它。

  • Active approach:

    主动方式:

    Here the process acquires only requires resources but whenever a new resource requires it must first release all the resources.

    在这里,过程仅获取需要的资源,但是每当需要新资源时,它都必须首先释放所有资源。

  • Wait time out:

    等待超时:

    Here there is a maximum time bound until which a process can wait for other resources after which it must release the resources.

    这里有一个最大的时间限制,在此之前,进程必须等待其他资源,然后才能释放资源。

  • Circular wait:

    循环等待:

    In order to remove circular wait, we assign a number to every resource and the process can request only in the increasing order otherwise the process must release all the high number acquires resources and then make a fresh request.

    为了消除循环等待,我们为每个资源分配了一个编号,该流程只能按递增顺序请求,否则该流程必须释放所有高编号获取的资源,然后提出新的要求。

  • No pre-emption:

    无抢占:

    In no pre-emption, we allow forceful pre-emption where a resource can be forcefully pre-empted. The pre-empted resource is added to the list of resources where the process is waiting. The new process can be restarted only when it regains its old resources. Priority must be given to a process which is in waiting for state.

    在没有抢占的情况下,我们允许强制抢占,以便可以强制抢占资源。 被抢占的资源将添加到进程正在等待的资源列表中。 仅当重新获得旧资源时,才能重新启动新进程。 必须优先考虑处于等待状态的进程。

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }

3.避免死锁 (3. Deadlock avoidance)

Here whenever a process enters into the system it must declare maximum demand. To the deadlock problem before the deadlock occurs. This approach employs an algorithm to access the possibility that deadlock would occur and not act accordingly. If the necessary condition of deadlock is in place it is still possible to avoid feedback by allocating resources carefully.

在这里,只要有流程进入系统,它就必须声明最大需求。 在出现死锁之前先解决死锁问题。 这种方法采用一种算法来访问可能发生死锁而不采取相应措施的可能性。 如果死锁的必要条件到位,则仍然可以通过仔细分配资源来避免反馈。

A deadlock avoidance algorithm dynamically examines the resources allocation state to ensure that a circular wait condition case never exists. Where the resources allocation state is defined by the of available and allocated resources and the maximum demand of the process. There are 3 states of the system:

避免死锁算法动态检查资源分配状态,以确保不存在循环等待条件的情况。 资源分配状态由可用资源和已分配资源以及进程的最大需求来定义。 系统有3种状态:

Safe state

安全状态

When a system can allocate the resources to the process in such a way so that they still avoid deadlock then the state is called safe state. When there is a safe sequence exit then we can say that the system is in the safe state.

当系统可以通过这种方式将资源分配给进程,以便它们仍然避免死锁时,该状态称为安全状态。 当存在安全序列退出时,我们可以说系统处于安全状态。

A sequence is in the safe state only if there exists a safe sequence. A sequence of process P1, P2, Pn is a safe sequence for the current allocation state if for each Pi the resources request that Pi can still make can be satisfied by currently available resources pulls the resources held by all Pj with j<i.

仅当存在安全序列时,序列才处于安全状态。 如果对于每个Pi来说Pi仍然可以提出的资源请求可以通过当前可用资源得到满足,则对于所有Pi而言 ,过程P1,P2,Pn的序列对于当前分配状态来说是一个安全序列,并且将所有Pj拥有的资源j <i

Methods for deadlock avoidance

避免死锁的方法

1) Resource allocation graph

1)资源分配图

This graph is also kind of graphical bankers' algorithm where a process is denoted by a circle Pi and resources is denoted by a rectangle RJ (.dots) inside the resources represents copies.

该图也是图形银行家算法的一种,其中过程用圆圈Pi表示,资源用矩形RJ(。点)表示,资源内部表示副本。

Presence of a cycle in the resources allocation graph is necessary but not sufficient condition for detection of deadlock. If the type of every resource has exactly one copy than the presence of cycle is necessary as well as sufficient condition for detection of deadlock.

资源分配图中存在循环是必要的,但不足以检测死锁。 如果每个资源的类型都只有一个副本,则必须要有周期,并且要有足够的条件来检测死锁。

This is in unsafe state (cycle exist) if P1 request P2 and P2 request R1 then deadlock will occur.

如果P1请求P2和P2请求R1处于不安全状态(存在循环),则将发生死锁。

2) Bankers’s algorithm

2)银行家算法

The resource allocation graph algorithms not applicable to the system with multiple instances of the type of each resource. So for this system Banker’s algorithm is used.

资源分配图算法不适用于具有每种资源类型的多个实例的系统。 因此,对于该系统,使用Banker的算法。

Here whenever a process enters into the system it must declare maximum demand possible.

在这里,每当流程进入系统时,它都必须声明可能的最大需求。

At runtime, we maintain some data structure like current allocation, current need, current available etc. Whenever a process requests some resources we first check whether the system is in a safe state or not meaning if every process requires maximum resources then is there ant sequence in which request can be entertaining if yes then request is allocated otherwise rejected.

在运行时,我们维护一些数据结构,例如当前分配,当前需求,当前可用等。每当一个进程请求一些资源时,我们首先检查系统是否处于安全状态,这意味着每个进程是否需要最大的资源,然后有蚂蚁序列如果是,则可以招待请求,然后分配请求,否则拒绝。

Safety algorithm

安全算法

This algorithm is used to find whether system is in safe state or not we can find

该算法用于发现系统是否处于安全状态

    Remaining Need = Max Need – Current allocation

    Current available = Total available – Current allocation
.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }

Let's understand it by an example:

让我们通过一个例子来理解它:

Consider the following 3 process total resources are given for A= 6, B= 5, C= 7, D = 6

考虑以下三个过程总资源,其中A = 6,B = 5,C = 7,D = 6

First we find the need matrix by Need= maximum – allocation

首先,我们通过Need = maximum-分配找到需求矩阵

Then find available resources = total – allocated

然后找到可用资源=总计–已分配

    A   B   C  D( 6   5  7  6) -   A  B  C  D(  3  4  6  4
Available resources A B C D(  3 1  1   2)

Then we check whether the system is in deadlock or not and find the safe sequence of process.

然后,我们检查系统是否处于死锁状态,并找到安全的处理顺序。

P1 can be satisfied

P1可以满足

    Available= P1 allocated + available
( 1, 2, 2, 1) +( 3, 1, 1,2) = (4, 3, 3, 3)

P2 can be satisfied

P2可以满足

    Available= P2 allocated + available
(1, 0, 3, 3) + (4, 3, 3, 3) = (5, 3, 6, 6)

P3 can be satisfied

P3可以满足

    Available= P3 allocated + available
(1, 2, 1, 0) + (5, 3, 6, 6) = (6, 5, 7, 6)

So the system is safe and the safe sequence is P1 → P2 → P3

因此系统是安全的,安全顺序为P1→P2→P3

4.检测与恢复 (4. Detection and recovery)

When the system is in deadlock then one method is to inform the operates and then operator deal with deadlock manually and the second method is system will automatically recover from deadlock. There are two ways to recover from deadlock:

当系统处于死锁状态时,一种方法是通知操作人员,然后由操作员手动处理死锁,第二种方法是系统将自动从死锁状态中恢复。 有两种方法可以从死锁中恢复:

  • Process termination:

    流程终止:

    Deadlock can be eliminated by aborting a process. Abort all deadlock process. Abort is processed at a time until the deadlock cycle is eliminated. This can help to recover the system from file deadlock.

    可以通过中止进程来消除死锁。 中止所有死锁过程。 一次处理中止,直到消除死锁周期。 这可以帮助从文件死锁中恢复系统。

  • Resources preemption:

    资源抢占:

    To eliminate deadlock using resources preemption, we prompt the same resources pas processes and give these resources to another process until the deadlock cycle is broken.

    为了使用资源抢占消除死锁,我们会提示使用相同的资源pas进程,并将这些资源分配给另一个进程,直到打破死锁周期为止。

    Here a process is partially rollback until the last checkpoint or and hen detection algorithm is executed.

    在此,过程将部分回滚,直到执行最后一个检查点或母鸡检测算法为止。

翻译自: https://www.includehelp.com/operating-systems/deadlock-and-method-for-handling-deadlock.aspx

死锁 预防死锁避免死锁

死锁 预防死锁避免死锁_死锁和处理死锁的方法相关推荐

  1. mysql死锁和索引的关系_奇怪的mysql死锁,当有外键索引的时候,会需要请求对关联表的锁吗?...

    请教数据库死锁问题,现象是在回复帖子的时候出现死锁 以下是mysql show innodb status结果: InnoDB |      | =========================== ...

  2. 死锁的充分必要条件、死锁预防、死锁避免、死锁检测和解除

    2.19.2 死锁的条件 必要条件 互斥:一次只有一个进程可以使用一个资源 占有且等待:当进程等待其他资源时继续占有已有的资源 不可抢占:进程不能强行占有其他进程占有的进程 充分条件 循环等待:存在一 ...

  3. 死锁预防之银行家算法

    死锁预防之银行家算法 死锁 死锁的定义 死锁的产生 死锁的描述 死锁避免算法 银行家算法 设计思想 分析 使用数据结构的描述 使用到的函数 主函数执行的流程 银行家算法的逻辑 完整的程序代码 运行结果 ...

  4. 死锁预防、死锁避免、死锁检测

    死锁 1.死锁的概念 1.1死锁的定义 多个进程并发执行,由于竞争资源而造成的一种僵局(互相等待),若无外力作用,这些进程都将无法推进,这就是死锁现象. 例如:系统中只有一台打印机和一台输入设备,若进 ...

  5. 死锁-死锁预防、死锁避免(资源分配图与银行家算法)、死锁检测、死锁解除

    文章目录 1 死锁 2 死锁预防 3 死锁避免 4 死锁检测 5 死锁解除 6 参考文献 1 死锁 什么是死锁     通俗的讲,就是两个或多个进程无限期的阻塞.相互等待的一种状态.比如哲学家进餐问题 ...

  6. 操作系统中的死锁_操作系统中的死锁介绍

    操作系统中的死锁 1.1究竟什么是僵局? (1.1 What exactly is a deadlock?) In a multiprogramming environment, there may ...

  7. go语言 mysql卡死_一次mysql死锁的排查过程-Go语言中文社区

    一次mysql死锁的排查过程一.背景17号晚上要吃饭了,看旁边的妹子和佐哥还在调代码,就问了下什么问题啊,还在弄,妹子说,在测试环境测试给用户并发发送卡券时,出现了死锁,但看代码没有死锁,问题如下图 ...

  8. sql server死锁_了解SQL Server死锁图的图形表示

    sql server死锁 #contentor img { float: left; } #contentor img { float: left; } 介绍 (Introduction) If yo ...

  9. 死锁产生的原因及条件、如何避免死锁

    一.死锁的定义 是指两个或两个以上的进程在执行过程中,由于竞争资源或者由于彼此通信而造.成的一种阻塞的现象,若无外力作用,它们都将无法推进下去.此时称系统处于死锁状态或系统产生了死锁,这些永远在互相等 ...

最新文章

  1. 开发ProxyServer的时候如何在一台PC上调试
  2. Go之十大经典排序算法
  3. QQ vs 360的战争之我见
  4. shell脚本安装python_shell脚本安装python、pip
  5. 关于 java.lang.OutOfMemoryError: Java heap space
  6. 链式添加_涂料导电炭黑添加量
  7. mac下8080端口到80端口的转发
  8. [原]减小VC6编译生成的exe文件的大小
  9. HCIA-RS(2019最新题库)
  10. 简明python教程gitbook_简明Python教程 Byte of Python
  11. 一次量产恢复U盘真实容量的操作过程(安国主控芯片)
  12. 微信音频silk导出多个mp3,合并成一个mp3,压缩大小
  13. linux usb有线网卡驱动_linux系统下安装usb网卡驱动图文?
  14. 5年磨一剑|优酷Android包瘦身治理思路全解
  15. 苹果AppStore审核,技术支持网址不通过被拒绝
  16. iOS10 关于推送
  17. systemd wsl 测试笔记
  18. 酷狗音乐车载Android版,酷狗音乐车载版
  19. element ui dialog custom-class不生效最终解决办法
  20. 九个问题从入门到熟悉HTTPS

热门文章

  1. python进行数据分析需要安装哪两个库_对Python进行数据分析_关于Package的安装问题...
  2. Redis(八):Zset有序集合数据类型详解
  3. p批处理替换目录下文本中的字符串
  4. Linux的标准I/O和管道
  5. 视频AI,助力体育赛事转播走进智能时代
  6. Fresco 二三事:图片处理之旋转、缩放、裁剪切割图片
  7. C#中IDisposable 回收非托管资源
  8. html跨浏览器兼容性问题
  9. Exchange收件人管理
  10. 明白90/10的原理吗?