Banker algorithm Example __ National Computer test four Grade

Source: Internet
Author: User

Recently began to prepare for the computer level four, basically did not encounter any problems, I feel that the computer level four is to test the understanding of memory, the banker algorithm is a problem in the computer four of the few computational problems.

Example 1. There are three types of resources (A,B,C) and five processes (P1,P2,P3,P4,P5) in the system, and the number of 17,B resources is the number of 6,c resources is 19. The status of the system at T0 time is as follows:

 

Maximum resource Demand

amount of allocated resources

 

A,b,c

A,b,c

P1

4,0,11

4,0,5

P2

5,3,6

4,0,2

P3

4,2,5

2,1,4

P4

5,5,9

2,1,2

P5

4,2,4

3,1,3

The system uses banker's algorithm to implement deadlock avoidance strategy, if the current system remaining resources (A,B,C) are (2,3,3) respectively, which one of the following sequence is a security sequence.

A.P3,P1,P4,P2,P5

B.P1,P3,P5,P2,P4

C.P4,P2,P3,P5,P1

D.P2,P3,P1,P4,P5

Almost all the data on the single selection of the Banker's algorithm are similar, so let's explain what a security sequence is before solving the problem. A security sequence is the security of a process sequence {P1,...,PN}, that is, for each process pi (1≤i≤n), it will not be required to exceed the current amount of resources in the system and all processes PJ (J < i) currently occupies the same amount of resources. This sentence is more abstract, we understand in the process of parsing.

Parsing: We first figure out the amount of resources that are needed for each process, the amount of resources that are required = the maximum resource requirement-the amount of resources allocated, and the amount of resources that are required for each process to be

P1 P2 P3 P4 P5
A,b,c 0,0,6 1,3,4 2,1,1 3,4,7 1,1,1
Next, we analyze the option a,p3 the amount of resources required (2,1,1), and the system remaining resources (2,3,3), so the process P3 process to complete, and release the amount of resources it occupies, that is, the amount of resources allocated, the system remaining resources (2+2,3+1,3+4) = (4,4,7), (4,4,7) is greater than (or equal to) the amount of resources that are required by all other processes (that is, P1,P1,P2,P4,P5) (note that the "greater than" here refers to the A,b,c three categories are greater than each), so the sequence of option A is a security sequence

Option B:P1 the required resource is (0,0,6), obviously the system remaining resources do not meet the conditions, B is a restless whole sequence.

Option C:P4 the required resource is (3,4,7), obviously the system surplus resources do not meet the conditions, C for the restless whole sequence.

Option D:P2 the required resource is (1,3,4), obviously the remaining resource of the system satisfies the condition, D is the restless whole sequence.

Almost every single choice of banker algorithm can be killed with one eye in the above method, of course, this is only the prelude to computer four, in single selection, we can easily choose the answer through the elimination method, but the computer four is a multiple-choice, multiple selection of the banker algorithm may have to spend more than a minute to determine the correct options, Be careful and careful, you can't turn your head around. There is a great chance of error. Here is a number of algorithms on the banker's multiple-choice, feel it, but also easy.

Example 2. The current resource allocation for an operating system is shown in the following table.

Process

Maximum Resource requirements

number of allocated resources

 

R1 R2 R3

R1 R2 R3

P1

7 5 3

0 1 0

P2

3 2 2

2 0 0

P3

9 0 2

3 0 2

P4

2 2 2

2 1 1

P5

4 3 3

0 0 2

assuming that the current system available resources R1, R2, and R3 are (3,3,2) and that the system is currently in a secure state, which of the following are security sequences.

a.p2p4p5p1p3

B.P2P4P5P3P1

C.P4P1P2P3P5

D.P3P2P5P4P1

E.P4P2P3P5P1 Resolution: Method See Example 1.

Answer: ABE

about the expansion of the Banker algorithm: (The following is "National computer grade four course--Operating system Principle" original)

The banker algorithm is to determine how to allocate resources by dynamically detecting resource allocation in the system and the requirements of the process to the resource, and to ensure the system is in a safe state before allocating resources to the requester, thus avoiding the system deadlock. Since the banker algorithm is implemented during the operation of the system, it takes a considerable amount of time and the algorithm requires mxn² operations. The banker algorithm requires that the quantity of each type of resource is fixed, and that the maximum demand for resources must be known beforehand, which is difficult to achieve. An unsafe state is not necessarily a deadlock state, and if a process requests a resource that is currently available, the process must wait for the resource utilization to drop.

Resources:

"1" National computer grade four tutorial--operating system principle

"2" National computer Grade Test level four network engineer future Education question Bank

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.