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

操作系统中的死锁

1.1究竟什么是僵局? (1.1 What exactly is a deadlock?)

In a multiprogramming environment, there may be several processes with a finite number of resources. A process may request another resource while still holding some of the other resources with itself. If these requested resources are not available at the time, the process may enter into a waiting state. This waiting state may never end if the resources requested by this process are held by other waiting processes. This situation is called "Deadlock" where none of the processes are ready to release their resources and are also waiting indefinitely for other waiting processes to release their resources.

在多程序环境中,可能会有几个进程使用有限数量的资源。 一个进程可能会请求另一个资源,同时仍然保留其他一些资源。 如果这些请求的资源当时不可用,则过程可能会进入等待状态。 如果此进程请求的资源由其他等待进程持有,则此等待状态可能永远不会结束。 这种情况称为“死锁” ,其中没有一个进程准备释放它们的资源,并且也无限期地等待其他等待的进程释放它们的资源。

1.2系统模型 (1.2 System Model)

  1. A system consists of a finite number of resources and these resources are partitioned into several types, each consisting of some number of identical instances.

    一个系统由有限数量的资源组成,并且这些资源被分为几种类型,每种类型都由一定数量的相同实例组成。

  2. Resource types include the printer, DVD drives, CPU cycles, files, etc. For example, if a system has two printers then the resource type Printer has two instances.

    资源类型包括打印机,DVD驱动器,CPU周期,文件等。例如,如果系统有两台打印机,则资源类型“打印机”有两个实例。

  3. These instances may be identical or different. If the instances are similar, any instance can be assigned to the process, and if not, then the two printers need to be defined as separate resource classes.

    这些实例可以相同或不同。 如果实例相似,则可以将任何实例分配给该流程,否则,则需要将两个打印机定义为单独的资源类。

  4. A process must request the resource before using it and must release it after use.

    进程必须在使用资源之前请求资源,并且在使用之后必须释放资源。

  5. A process may request as many resources as it requires for the completion of its task but it should not exceed the total number of resources present in the system.

    进程可以请求完成任务所需的资源,但是它不应超过系统中存在的资源总数。

  6. To summarize, a process must utilize a resource in the following manner,

    总而言之,流程必须以以下方式利用资源:

    • Request: The process must request for the resource. If the request can't be granted immediately, it must wait to acquire the resource.请求 :进程必须请求资源。 如果无法立即批准该请求,则它必须等待获取资源。
    • Use: The process must use the resource after acquiring it.使用 :流程必须在获取资源后使用它。
    • Release: The process must release the resource after using it.释放 :进程必须在使用后释放资源。

1.3死锁特征 (1.3 Deadlock Characterization)

There are four necessary conditions for a deadlock to occur. If any of the four conditions fail, then the condition is not called a deadlock and maybe recovered easily. The following are the necessary conditions,

发生死锁有四个必要条件。 如果这四个条件中的任何一个失败,则该条件不称为死锁,并且可能容易恢复。 以下是必要条件,

1.3.1 Mutual Exclusion

1.3.1互斥

At least one resource must be held in a non-sharable mode. This means that only one process can use the resource at a particular time. If any other process requests this non-sharable resource, then, it must wait for the process which is holding the resource to release it.

至少一种资源必须处于不可共享的模式。 这意味着在特定时间只有一个进程可以使用资源。 如果任何其他进程请求此不可共享资源,则它必须等待持有该资源的进程释放它。

If we think clearly, this is a necessary condition for deadlock because if more than one process is allowed to use a resource at the same time, the deadlock will never occur and all the resources will carry out their tasks easily.

如果我们想清楚,这是死锁的必要条件,因为如果允许多个进程同时使用一个资源,则死锁将永远不会发生,所有资源将轻松执行其任务。

1.3.2 Hold and Wait

1.3.2保持并等待

A process must be holding at least one resource and waiting to acquire other resources that are currently being held by other processes.

一个进程必须至少持有一种资源,并等待获取其他进程当前正在持有的其他资源。

1.3.3 No preemption

1.3.3无抢占

The resources cannot be preempted. What this means is that one process cannot snatch a resource from another process that currently holds it. It can only be released voluntarily by the process holding it after its execution.

资源不能被抢占。 这意味着一个进程无法从当前拥有该进程的另一进程中抢夺资源。 它只能在执行后由持有它的进程自动释放。

1.3.4 Circular Wait

1.3.4循环等待

A set {P0, P1, ..., Pn} of waiting process must exist such that P0 is waiting for a resource held by P1, P1 is waiting for a resource held by P2, …, Pn-1 is waiting for a resource held by Pn, and Pn is waiting for a resource held by P0.

必须存在一组{P0,P1,...,Pn}等待过程,这样P0正在等待P1拥有的资源,P1正在等待P2拥有的资源,...,Pn-1正在等待资源Pn持有,而Pn正在等待P0持有的资源。

The circular wait condition implies the hold and waits for condition, so these four conditions are not independent as we shall see in the next article.

循环等待条件暗含保持和等待条件,因此这四个条件不是独立的,我们将在下一篇文章中看到。

1.4资源分配图 (1.4 Resource Allocation Graph)

Resource allocation graphs are mainly used as methods for the detection of a deadlock. We will discuss this feature when we read about Deadlock Handling mechanisms.

资源分配图主要用作检测死锁的方法。 当我们阅读有关死锁处理机制时,我们将讨论此功能。

  1. Deadlock can be best represented in the terms of a directed graph called a system resource-allocation graph. The graph consists of a set of vertices V and a set of edges E.

    死锁最好用称为系统资源分配图的有向图来表示 。 该图由一组顶点V和一组边E组成

  2. The edges can be of two types, represented as Pi for a process i and Rj for a resource type j, where i, j are the integer values representing the number of processes and resource types respectively.

    边缘可以是两种类型,分别表示为进程i的 Pi和资源类型j的 Rj ,其中i,j是分别表示进程数和资源类型的整数值。

  3. The vertices V are partitioned into two different types of nodes: P = {P1, P2, ..., Pn}, the set consisting of all the active processes in the system, and R = {R1, R2, ..., Rm}, the set consisting of all the resource types in the system.

    顶点V分为两个不同类型的节点: P = {P1,P2,...,Pn} ,该集合由系统中所有活动进程组成, R = {R1,R2,..., Rm} ,由系统中所有资源类型组成的集合。

  4. A directed edge from process Pi to resource type Rj is denoted by PiRj. It shows that process Pi is requesting an instance of resource type Rj and is called a request edge.

    Pi到资源类型Rj的有向边用PiRj表示。 它显示进程Pi正在请求资源类型Rj的实例,并且被称为请求边缘。

  5. A directed edge from resource type Rj to process Pi is denoted by RjPi. It shows that an instance of resource type Rj is allocated to process Pi and is called an assignment edge.

    从资源类型Rj到进程Pi的有向边用RjPi表示。 它显示资源类型Rj的实例已分配给进程Pi ,称为分配边缘。

  6. Pictorially, each process Pi is represented as a circle and each resource type Rj as a rectangle. Since there may be more than one instance of a resource, the instances are denoted by a dot within the rectangle.

    如图所示,每个进程Pi表示为一个圆形,每个资源类型Rj表示为一个矩形。 由于资源的实例可能不止一个,因此实例在矩形内用一个点表示。

  7. When process Pi requests and instance of a resource type Rj, a request edge is inserted in the graph. When the request is fulfilled, the request edge is instantaneously transformed into an assignment edge. When the process completes its work, it releases the resource; as a result, the assignment edge is deleted.

    当进程Pi请求资源类型为Rj的实例时,请求边将插入图中。 当请求被满足时,请求边被立即转换为分配边。 流程完成工作后,将释放资源。 结果,分配边被删除。

Consider a few examples,

考虑几个例子,

  • The sets P, R, and E:

    集合P,R和E:

    • P = {P1, P2, P3}
    • R = {R1, R2, R3, R4}
    • E = {P1 → R1, P2 → R3, R1 → P2, R2 → P2, R2 → P1, R3 → P3}
  • Resource instances:

    资源实例:

    • One instance of resource type R1
    • Two instances of resource type R2
    • One instance of resource type R3
    • Three instance of resource type R4


    • Introduction to Deadloack | Image 1


      Fig 1.1 Resource Allocation Graph图1.1资源分配图
  • Process states:

    流程状态:

    • Process P1 is holding an instance of resource type R2 and is waiting for an instance of resource type R1.
    • Process P2 is holding an instance of R1 and an instance of R2 and is waiting for an instance of R3.
    • Process P3 is holding an instance of R3.
  • This resource allocation graph shows that there is no cycle in the graph. Therefore, no process in the system is deadlocked. If the graph does contain a cycle, then a deadlock may exist. This depends on two situations as follows.

    此资源分配图显示图中没有循环。 因此,系统中的任何进程都不会陷入僵局。 如果图形确实包含一个循环,则可能存在死锁。 这取决于以下两种情况。

IMPORTANT POINTS TO NOTE:

注意要点:

  1. If each resource type has exactly one instance, then a cycle implies that a deadlock has occurred. Each process in the cycle is deadlocked. In this case, a cycle in the graph is both a necessary and sufficient condition for the existence of deadlock.

    如果每种资源类型仅具有一个实例,则循环表示发生了死锁。 循环中的每个进程都处于死锁状态。 在这种情况下,图中的循环既是存在死锁的必要条件,也是充分条件。

  2. If each resource has several instances, then a cycle is not the necessary condition to determine that deadlock has occurred.

    如果每个资源都有多个实例,则循环不是确定发生死锁的必要条件。

  3. To illustrate this concept, we include a request edge from P3 → R2.

    为了说明这个概念,我们包括一个从P3→R2的请求边。

Introduction to Deadloack | Image 2


Fig 1.2 Resource Allocation Graph (Cycle with deadlock)

图1.2资源分配图(带有死锁的周期)

Here, there are two cycles present in the system:

在这里,系统中存在两个周期:

    P1 → R1 → P2 → R3 → P3 → R2 → P1
P2 → R3 → P3 → R2 → P2

CONCLUSION: Processes P1, P2, and P3 are deadlocked.

结论:进程P1,P2和P3处于死锁状态。

Now, consider another graph where the following cycle exists:

现在,考虑存在以下循环的另一个图:

    P1 → R1 → P3 → R2 → P1

CONCLUSION: There is no deadlock. The process P4 may release its instance of resource type R2. That resource can then be allocated to P3, breaking the cycle.

结论:没有死锁。 过程P4可以释放其资源类型R2的实例。 然后可以将该资源分配给P3,从而中断周期。

Introduction to Deadloack | Image 3


Fig 1.3 Cycle but no deadlock

图1.3循环但无死锁

To summarize: If a resource allocation graph does not have a cycle, then the system is not in a deadlocked state. If there is a cycle, then the system may or may not be in a deadlocked state. When there are multiple instances of a resource type, the presence of a deadlock is determined using Banker's Algorithm. We will study that in further articles.

总结一下:如果资源分配图没有周期,则系统不会处于死锁状态。 如果存在周期,则系统可能处于死锁状态,也可能未处于死锁状态。 当资源类型有多个实例时,使用Banker算法确定死锁的存在。 我们将在后续文章中对此进行研究。

References:

参考文献:

  • Operating System Concepts, 8th edition, by author: Silberschatz Galvin Gagne.

    操作系统概念,第8版,作者:Silberschatz Galvin Gagne。

  • Operating System Design/Concurrency/Deadlock

    操作系统设计/并发/死锁

  • Deadlock

    僵局

  • Hold and wait a process must be holding at least one

    保持并等待一个进程必须至少持有一个

  • Chapter 6 Deadlocks

    第六章僵局

翻译自: https://www.includehelp.com/operating-systems/introduction-of-deadlock.aspx

操作系统中的死锁

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/541353.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

centos配置ipv6地址

首先打开网站注册一个账号:http://www.tunnelbroker.net创建一个ipv6的地址:把下面的命令在linux上执行一遍,这个方式是临时生效,重启网卡和重启系统自动失效。把上面的命令保存到一个配置文件中:vi /etc/sysconfig/ne…

NFS部署及优化(一)

NFS部署及优化(一)一、NFS的基本概念NFS network file system 网络文件系统必然通过网络通信来实现文件的访问和写入,所以做这个实验的话最好有两台虚拟机配置:A:一个192.169.50.201为server端B:一个192.169.50.200为…

HDU 4923 Room and Moor(瞎搞题)

瞎搞题啊。找出1 1 0 0这样的序列,然后存起来,这样的情况下最好的选择是1的个数除以这段的总和。然后从前向后扫一遍。变扫边进行合并。每次合并。合并的是他的前驱。这样到最后从t-1找出的那条链就是最后满足条件的数的大小。Room and Moor Time Limit:…

linux下的文件系统,Linux根文件系统(“/”文件系统)下的目录介绍

Linux下的文件存储与Windows完全不同,Windows将系统文件存储在系统盘(比如说C:\下)Linux根本没有盘符到概念只有一个根文件系/,各个磁盘分区挂载在/media/下(或者/mnt/下)/下到如/etc,/proc,/bin,/dev,lib等很是让用惯了Windows的用户不解,下…

greenlet 详解

greenlet初体验回到顶部Greenlet是python的一个C扩展,来源于Stackless python,旨在提供可自行调度的‘微线程’, 即协程。generator实现的协程在yield value时只能将value返回给调用者(caller)。 而在greenlet中,target.switch&am…

详细图解mongodb 3.4.1 win7x64安装

原文:http://www.cnblogs.com/yucongblog/p/6895983.html 详细图解,记录 win7 64 安装mongo数据库的过程。安装的版本是 MongoDB-win32-x86_64-2008plus-ssl-3.4.1-signed。 我下载的源文件:mongodb-win32-x86_64-2008plus-ssl-3.4.1-signed我…

linux用ping命令测试网速,linux下面使用命令测试网速

大家都知道在speedtest是市面上最准确最全面的测速工具,但在linux命令行不能直接使用,所以我们就借助脚本调用speedtest的接口来利用他测试网速。1.下载speedtest-cli脚本:下载地址:https://raw.githubusercontent.com/sivel/spee…

rocksdb ubuntu c++源码编译测试

2019独角兽企业重金招聘Python工程师标准>>> 环境: ubuntu16.4 需要安装 snappy gflage bz2 zstd 以及g 其中zstd是facebook开放源代码里的压缩的库 git clone https://github.com/facebook/rocksdb.git cd rocksdb make static_lib 成功生成 librocksd…

NABARD的完整形式是什么?

NABARD:国家农业和农村发展银行 (NABARD: National Bank for Agriculture and Rural Development) NABARD is an abbreviation of National Bank for Agriculture and Rural Development. NABARD是国家农业和农村发展银行的缩写 。 On 12 July 1982, it was establ…

基于opencv+Dlib的面部合成(Face Morph)

引自:http://blog.csdn.net/wangxing233/article/details/51549880 零、前言 前段时间看到文章【1】和【2】,大概了解了面部合成的基本原理。这两天空下来了,于是参考【3】自己实现了下。虽然【1】和【2】已经讲的很清楚了,但是有…

大脑应对危机的模式_危机的完整形式是什么?

大脑应对危机的模式危机:印度信用评级信息服务有限公司 (CRISIL: Credit Rating Information Services of India Limited) CRISIL is an abbreviation of Credit Rating Information Services of India Limited. It is an international analytic company which off…

linux网络延迟命令,2. Linux使用ping命令查看网络延迟

ping命令持续发送少量互联网流量到远程地址并报告收到回应的总时间。如果流量因为网络故障或者错误配置而被丢弃,它也会报告。ping命令是最基本和初级的诊断网络问题的工具之一。ping常被用来测试网络延迟,但是有时ping的延迟并不是网络引起的&#xff0…

linux查看磁盘io带宽,[Linux] 磁盘IO性能查看和优化以及iostat命令

iostat命令:%user:CPU处在用户模式下的时间百分比。%nice:CPU处在带NICE值的用户模式下的时间百分比。%system:CPU处在系统模式下的时间百分比。%iowait:CPU等待输入输出完成时间的百分比。%steal:管理程序维护另一个虚…

Jsoup 数据修改

2019独角兽企业重金招聘Python工程师标准>>> 1 设置属性的值 在解析一个Document之后可能想修改其中的某些属性值,然后再保存到磁盘或都输出到前台页面。 可以使用属性设置方法 Element.attr(String key, String value), 和 Elements.attr(String key, S…

软件静态架构 软件组件图_组件图| 软件工程

软件静态架构 软件组件图什么是组件图? (What is Component Diagram?) A Component Diagram breaks down the real system under development into different heights of working. Every component is reactive for the main aim in the entire system and only re…

如何卸载非linux系统分区,如何卸载Linux系统分区?卸载Linux系统分区的方法-站长资讯中心...

系统为windows xp sp2和redhat as 5双系统,其中linux系统后安装的在D盘,华彩软件站www.huacolor.com小编今天发现硬盘不够用了,想干掉linux分区,在虚拟机中用linux。就在windows的磁盘管理(命令为:diskmgmt)下删除linux分区&#…

顺序结构复习

复习一些易错知识点还有习题 目录 可能不熟悉的知识点 逻辑表达式的求解 if,else的配队 条件运算符 运算符优先级的问题 switch的使用 goto和if构成的循环 例题讲解 1 2 3 4 ​编辑 5 ​编辑 6赋值 ​编辑 7 可能不熟悉的知识点 逻辑表达式的求解 如果…

模板模式(部分方法延迟到子类实现)

项目中,用到了抽象类作为父类,有部分实现。 提供了了模板方法作为子类公共方法,模板方法中调用了抽象类的抽象方法和部分非抽象方法。 执行代码时,发现模板方法调用了抽象类的抽象方法,当时比较好奇,后来发…

【转载】浏览器缓存详解:expires cache-control last-modified

下面的内容展示了一个常见的 Response Headers,这些 Headers 要求客户端最多缓存 3600 秒,也给出了一个 pub1259380237;gz 的校验值。 HTTP/1.x 200 OK Transfer-Encoding: chunked Date: Sat, 28 Nov 2009 04:36:25 GMT Server: LiteSpeed Connection: …

linux下php的安装,Linux下PHP安装

1 下载php源码安装包 个人是php-5.6.30.tar.gzphp2 解压文件mysqltar -zxvf php-5.6.30.tar.gznginx3 编译安装sqlcd php-5.6.30api建立www用户和www用户组curlgroupadd wwwsocketuseradd -g www wwwphp-fpm在编译以前先把依赖包都装上urlyum install curl curl-develyum inst…