问题 问答题

阅读下列说明和图,回答问题1到问题3,将解答填入对应栏内。

[说明]

操作系统中,死锁(Deadlock)是指多个进程在运行的过程中因争夺资源而造成的一种僵局。当进程处于这种僵持状态时,若无外力作用,它们都将无法再向前推进。

面对死锁问题有两个解决方案:预防死锁和避免死锁。

预防死锁是一种较简单和直观的事先预防方法。该方法是通过设置某些限制条件,去破坏产生死锁的四个必要条件中的一个或多个,以此来预防死锁的发生。预防死锁由于较易实现,已被广泛应用,但由于所施加的限制条件往往太严格,可能会导致系统资源利用率和系统吞吐量的降低。

避免死锁同样是属于事先预防的策略,但它无须事先采取各种限制措施去破坏产生死锁的四个必要条件,而是在资源分配过程中,用某种方法去防止系统进入不安全状态,从而避免发生死锁。

银行家算法(Banker’s algorithm)是Dijkstra于1965年提出的一个经典的避免死锁的算法。形象地描述银行发放贷款不能使有限可用资金匮乏而导致整个银行无法运转的思路,也就是说每次请求贷款,银行要考虑他能否凭着贷款完成项目,并还清贷款使银行运转正常。令Request(i)是进程P(i)请求向量,如果Request(i)[j]=k则进程P(i)希望请韵类资源k个。具体算法步骤如下:

(1)如果Request(i)>Need(i)则出错(请求量超过申报的最大量),否则转到(2);

(2)如果Request(i)>Available则P(i)等待,否则转(3);

(3)系统对P(i)所请求的资源实施试探分配,并更改数据结构中的数值;

(4)Available=Available-Request(i);

A1location(i) =Allocation(i) +Request(i);

Need(i)=Need(i)-Request(i);

(5)执行安全性算法,如果是安全的,则承认试分配,否则废除试分配,让进程P(i)继续等待。

所谓系统是安全的,是指系统中的所有进程能够按照某一种次序分配资源,并且依次运行完成,这种进程序列P1,P2,…,Pn)就是安全序列。如果存在这样一个安全序列,则系统是安全的;如果系统不存在这样一个安全序列,则系统是不安全的。

简述产生死锁的四个必要条件。

答案

参考答案:

死锁的发生必须具备四个必要条件:

互斥条件:进程对所分配到的资源进行排他性使用,即在一段时间内某资源只有一个进程占用;

请求和保持条件:进程已经保持了至少一个资源但又提出了新的资源请求,若得不到满足则阻塞该进程,但其保持已获得的资源不释放;

不剥夺条件:进程已获得的资源,在未使用完之前,不能被剥夺,只能在使用完时由自己释放;

环路等待条件:在发生死锁时,必然存在一个进程一资源的环形链,即进程集合{P1,P2,…,Pn)中的P1等待P2占用的资源,P2等待P3占用的资源,…,Pn等待P0占用的资源。

单项选择题
填空题

Old people are always saying that the young are not what they were. The same comment is made from generation to generation and it is always true. It has never been truer than it is today. The young are better (1)edu . They have a lot more money to spend and enjoy more freedom. They grow up more quickly and are not so (2)de on their parents. They think more for themselves and do not blindly (3)a the ideas of their (4)e . Events which the older generation remembers clearly are nothing (5)m than past history. This is as it should be. Every new generation is different from the one that preceded it. Today the difference is very marked indeed.
The old always assume that they know best for the simple reason (6)t they have been around a bit longer. They don’t like to feel that their values are being (7)qu or threatened. And this is precisely what the young are doing. They are questioning the assumptions of their elders and (8)dis their self-satisfaction. They take leave to doubt the older generation has created the best of all possible worlds. What they reject more than anything is conformity.
Who said that human differences can best be solved through conventional politics or by violent means Why have the older generation so often used (9)vi to their problems Why are they so unhappy and so troubled by a sense of guilt in their personal lives, so (10)oc with mean ambitions and the desire to accumulate more and (11)m material possessions Haven’t the old lost touch with all that is important in life
These are not questions the older generation can shrug off lightly. Their record over the past forty years or so hasn’t been exactly spotless. Traditionally, the young have (12)tu to their elders for guidance. Today, the situation might be (13)rev . The old—if they are prepared to admit it—could learn a thing or two from their children. One of the biggest lessons they could learn is that enjoyment is not "sinful". (14)En is a principle one could apply to all (15)as of life. It is surely not wrong to enjoy your work and enjoy your leisure. It is surely not wrong to live in the present rather than in the past or future.