Open In App

Relation Between Number of Processes and Number of Resources to Prevent Deadlock

A set of blocked processes where each process is holding some resource and waiting to acquire some other resource held by another process in the set. This situation is called deadlock in the operating system.

Deadlock can be prevented if the number of resource instances in a system is significantly larger than the number of processes asking for a resource. In this article, we are going to understand the relation between a number of processes and a number of resources to prevent deadlock based on the two following problem statements:



Problem 1

Calculate the minimum number of resources required.

Given the maximum number of resources asked by each process, calculate the minimum number of resources required to permanently avoid deadlock. Let us take the following example,



A given system has n processes and m instances of a certain resource type. The iᵗʰ process can ask at most Sresources. What is the minimum value of m, so that the system never enters into deadlock?

Approach

Now we just have add one to the The maximum number of resources that can lead to a deadlock to get the desired result. The calculation is as follows:

So the minimum number of resources required to avoid a deadlock is:

Problem 2

Calculate the maximum number of resources one process can ask?

Given the number of resources and number of processes available in the system, calculate the maximum number of resources one process can ask without leading to any deadlock combination.

A given system has n processes and m instances of a certain resource type. Each process can request maximum of k instances at a certain point of time. What is the largest value of k that will always avoid deadlock?

Approach

So the maximum number of resources one process can ask is (m + n – 1)/n.

Relevant GATE Questions

GATE CS 2018 | Question 30

GATE-CS-2006 | Question 85

GATE-CS-2005 | Question 90

GATE CS 1998 | Question 32

GATE CS 1997 | Question 47

ISRO CS 2009 | Question 16

Article Tags :