Process deadlock (Banker algorithm)

Source: Internet
Author: User

1. deadlock: There are many mutex resources (such as printers) or software resources (such as critical zones) in the computer system. If two processes use the printer at the same time or enter the critical zone at the same time, problems will inevitably occur. The so-called deadlock refers to the phenomenon that two or more processes require each other to continue running because of the resources occupied by the other party.

2. Conditions for deadlock:

(1) mutex condition: A resource can only be used by one process at a time. This is a real situation in the operating system.

(2) Persistence and waiting conditions: a process has obtained some resources, but the resources obtained are not allowed when other resources are requested to be blocked.

(3) Non-deprivation condition: Some system resources cannot be deprived. When a process has obtained such resources, the system cannot forcibly reclaim them and can only be released by itself when the process is used up.

(4) loop wait condition: several processes form a ring chain, each occupying the next resource requested by the other party.

3. deadlock prevention: the deadlock prevention adopts a certain policy to restrict concurrent process requests to resources and destroy one of the four necessary conditions for deadlock, the system does not meet the deadlock conditions at any time.

(1) pre-static allocation method. The "non-deprivation condition" is damaged ". Pre-allocate required resources to ensure that resources are not waiting. The problem with this method is that it reduces the request to resources and the concurrency of processes; sometimes it is impossible to know the required resources in advance.

(2) orderly resource allocation. The "loop condition" is damaged ". Classify resources in order. Make sure that no loop is formed. The problem with this method is to restrict the process's requests to resources because resource sorting occupies system overhead.

4. deadlock avoidance: The process determines whether these operations are safe each time it applies for resources. The typical algorithm is the Banker algorithm ". However, this algorithm increases system overhead.

5. Deadlock Detection: checks whether the system is in a deadlock state. If yes, executes the deadlock relief policy.

6. deadlock relief: used in combination with Deadlock Detection. The method used is deprivation. Forcibly allocate resources to other processes.

 

Banker algorithm:

Example: A system has four mutex resources: R1, R2, R3, and R4. The available resources are 3, 5, 6, and 8. Assume that there are four processes P1, P2, P3, and P4 at T0, and the maximum resource demand and allocated resources of these processes are shown in the following table, the remaining resources of R1, R2, R3, and R4 are(1). If the process starts from T0(2)The system status is secure for sequential scheduling and execution.

(1) A.3, 5, 6, and 8 B .3, 4, 2, and 2

C.0, 1, 2, and 1 d.0, 1, 0, and 1

(2) A. P1 → P2 → P4 → P3 B. P2 → P1 → P4 → p3

C. P3 → P2 → P1 → P4 D. P4 → P2 → P3 → p1

 

① Calculate the number of remaining resources

Use the number of available resources minus the number of allocated resources:

 

R1 = 3-(1 + 0 + 1 + 1) = 3-3 = 0

R2 = 5-(1 + 1 + 1 + 1) = 5-4 = 1

R3 = 6-(2 + 2 + 1 + 1) = 6-6 = 0

R4 = 8-(4 + 2 + 0 + 1) = 8-7 = 1

 

So (1) Select D.

 

② Determine the number of remaining resources

Analysis, because the remaining available resources are (,), compared with the above demand Resource number, only the P3 demand Resource number is met, so Abd is eliminated and C is selected.

Verify C. P3 → P2 → P1 → p4

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.