Source: Internet
Author: User

When learning the process in the operating system, the name of the Process deadlock is exposed. So what is a process deadlock?

Process deadlock means that if multiple processes simultaneously occupy the resources required by the other party and request the other party's resources at the same time, they will not release the occupied resources before obtaining the request, A deadlock occurs, that is, the process cannot be synchronized.

So how does a deadlock occur?

There are four conditions for deadlock generation:

Mutex condition: A resource can only be used by one process at a time (this is a real situation in the operating system)

Persistence and waiting condition: A process has obtained some resources, but the resources obtained are not allowed when the request for other resources is blocked.

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.

Loop wait condition: several processes form a ring chain, each occupying the next resource requested by the other party

The most representative way to avoid deadlocks is the bankers algorithm.

As for what the Banker algorithm is, I will not go into details here. To be honest, it is difficult to understand the concept alone, or to explain the example to understand what the Banker algorithm is.

Example: Suppose there are three types of mutex resources: R1, R2, and R3. The available resources are 9, 8, and 5. at the time of T0, the system has five processes: P1, P2, P3, P4, and P5. The maximum resource demand and allocated resources of these processes are as follows, if the process is executed in the ______ sequence, the system status is secure.

Solution Process:

From the process resource table given in the question, we can see that for resources R1, R2, and R3, they have already been allocated a part in advance. Now let's take a look at whether there is any surplus.

R1 = 9-(1 + 2 + 2 + + 1) = 2

R2 = 8-(2 + 1 + 1 + 2 + 1) = 1

R3 = 5-(1 + 1 + 3) = 0

At the same time, for the five processes, the system allocates a part of their respective resources, whether these resources can satisfy them, based on the need for resources = maximum demand-the number of allocated resources, the result is as follows:

 ResourcesProcess Maximum demandR1 R2 r3 Allocated resourcesR1 R2 r3 Remaining resourcesR1 R2 r3 Additional resources requiredR1 R2 r3 P1 6 5 2 1 2 1 2 1 0 5 3 1 P2 2 2 1 2 1 1 0 1 0 P3 8 1 1 2 1 0 6 0 1 P4 1 2 1 1 2 0 0 0 1 P5 3 4 4 1 1 3 2 3 1

Obviously, the "remaining resources" can only meet the requirements of process P2.

 ResourcesProcess Maximum demandR1 R2 r3 Allocated resourcesR1 R2 r3 Remaining resourcesR1 R2 r3 Additional resources requiredR1 R2 r3 P2 2 2 1 2 1 1 2 1 0 0 1 0

Then start to run the P2 process. After P2 is run, "allocated resources" must be released. The remaining resources = the remaining resources of the previous process + "allocated resources" (the execution of P2 has been completed)

 ResourcesProcess Maximum demandR1 R2 r3 Allocated resourcesR1 R2 r3 Remaining resourcesR1 R2 r3 Additional resources requiredR1 R2 r3 P2 2 2 1 2 1 1 4 2 1 0 1 0

According to the comparison, we can see that the "remaining resources" fully meet the process P4, and so on. We can get the final result table.

 ResourcesProcess Maximum demandR1 R2 r3 Allocated resourcesR1 R2 r3 Remaining resourcesR1 R2 r3 Additional resources requiredR1 R2 r3 2 1 0 P2 2 2 1 2 1 1 4 2 1 0 1 0 P4 1 2 1 1 2 0 5 4 1 0 0 1 P1 6 5 2 1 2 1 6 6 2 5 3 1 P5 3 4 4 1 1 3 8 7 2 2 3 1 P3 8 1 1 2 1 0 10 8 2 6 0 1

It is not difficult for bankers to calculate, mainly because it is complicated and requires patience in computing.

Related Keywords:

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.