Sei sulla pagina 1di 8

Name :- Aditya Yadav

Roll Number :- 3
Subject :- Operating System
Semester :- BCA 4th sem

Assignment:-2
Question:-1
Discuss the Critical section problem and its solution
Answer
The critical section is a code segment where the shared variables can be accessed.
An atomic action is required in a critical section i.e. only one process can execute in
its critical section at a time. All the other processes have to wait to execute in their
critical sections.
A diagram that demonstrates the critical section is as follows −

In the above diagram, the entry section handles the entry into the critical section. It
acquires the resources needed for execution by the process. The exit section
handles the exit from the critical section. It releases the resources and also informs
the other processes that the critical section is free.

Solution to the Critical Section Problem


The critical section problem needs a solution to synchronize the different processes.
The solution to the critical section problem must satisfy the following conditions −

 Mutual Exclusion
Mutual exclusion implies that only one process can be inside the critical
section at any time. If any other processes require the critical section, they
must wait until it is free.

 Progress
Progress means that if a process is not using the critical section, then it
should not stop any other process from accessing it. In other words, any
process can enter a critical section if it is free.

 Bounded Waiting
Bounded waiting means that each process must have a limited waiting time.
Itt should not wait endlessly to access the critical section.

Question:-2
Discuss in brief the problems of Process Synchronization (Bounded-Buffer Problem,
Readers–Writers Problem and Dining-Philosophers Problem)

Answer:
We present a number of synchronization problem as examples of large class of concurrency-
control problems. These problems are used for

do{

...

// produce an item in nextp

...

wait(empty);

wait(empty);

...

//add nextp to buffer

...

signal(mutex);

signal(full);

}while(TRUE);

Testing nearly every newly proposed synchronization scheme.

1. Bounded-buffer Problem:
Bounded Buffer problem is also called producer consumer problem. This problem is
generalized in terms of the Producer-Consumer problem. Solution to this problem is,
creating two counting semaphores “full” and “empty” to keep track of the current number
of full and empty buffers respectively. Producers produce a product and consumers
consume the product, but both use of one of the containers each time.

Readers and Writers Problem:


Suppose that a database is to be shared among several concurrent processes. Some of
these processes may want only to read the database, whereas others may want to update
(that is, to read and write) the database. We distinguish between these two types of
processes by referring to the former as readers and to the latter as writers. Precisely in OS
we call this situation as the readers-writers problem. Problem parameters:
 One set of data is shared among a number of processes.
 Once a writer is ready, it performs its write. Only one writer may write at a time.
 If a process is writing, no other process can read it.
 If at least one reader is reading, no other process can write.
 Readers may not write and only read.
Dining-Philosphers Problem:
The Dining Philosopher Problem states that K philosophers seated around a circular
table with one chopstick between each pair of philosophers. There is one chopstick
between each philosopher. A philosopher may eat if he can pickup the two
chopsticks adjacent to him. One chopstick may be picked up by any one of its
adjacent followers but not both. This problem involves the allocation of limited
resources to a group of processes in a deadlock-free and starvation-free manner.

Question:-3
Consider the following snapshot of a system in which five resources A, B, C, D and E are

available. The system contains a total of 2 instances of A, 1 of resource B, 1 of resource C, 2


resource D and 1 of resource E

Convert this matrix representation to a resource allocation graph

Answer
Question:-4
Consider the following resource allocation graph.

Convert it to the matrix representation (i.e., Allocation, Request and


Available).

Answer:-
1

Total value of A = 1(from P0) + 1(from P1) + 2(from Available)=4


Total value of B = 1(from P1) + 1from Available)=2
Total value of C = 1(from P0) + 1(from Available)=2
Total value of D = 1(from P0) + 1(from P2) + 2(from Available)=4
Total value of E = 1(from Available)=1

ALLOCATED REQUESTED AVAILABLE


A B C C R R R R R R R R R R R R R R
1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6
P1 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0
P2 1 0 0 1 0 0 0 1 0 0 0 0
P3 0 0 0 0 0 1 0 1 0 0 0 0
P4 0 1 0 1 0 0 0 0 0 0 0 1
P5 0 0 1 0 0 1 0 0 0 0 0 0

Question:-5
Q 5 : Consider the following snapshot of a system in which four resources A,
B, C and D area available. The system contains a total of 6 instances of A, 4 of
resource B, 4 of resource C, 2 resource D.

ALLOCATION MAX NEED AVAILBLE


A B C D A B C D A B C D A B C D
P0 2 0 1 1 3 2 1 1 6 4 4 2
P1 1 1 0 0 1 2 0 2
P2 1 0 1 0 3 2 1 0
P3 0 1 0 1 2 1 0 1

Do the following problems using the banker’s algorithm:

a) Compute what each process might still request and fill this in under the
column Need.
b) Is the system in a safe state? Why or why not?
c) Is the system deadlocked? Why or why not?
d) If a request from P3 arrives for (2,1,0,0), can the request be granted
immediately?

Solution :
A)

ALLOCATION MAX NEED AVAILBLE


A B C D A B C D A B C D A B C D
P0 2 0 1 1 3 2 1 1 1 2 0 0 6 4 4 2
P1 1 1 0 0 1 2 0 2 0 1 0 2
P2 1 0 1 0 3 2 1 0 2 2 0 0
P3 0 1 0 1 2 1 0 1 2 0 0 0

STEP:-1

P0’s Need = [1,2,0,0] ≤ Available = [6,4,4,2] (P0 satisfied)

ALLOCATION MAX NEED AVAILBLE


A B C D A B C D A B C D A B C D
P0 3 2 1 1 8 4 5 3
P1 1 1 0 0 1 2 0 2 0 1 0 2
P2 1 0 1 0 3 2 1 0 2 2 0 0
P3 0 1 0 1 2 1 0 1 2 0 0 0

STEP:-2
P1’s Need = [0,1,0,2] ≤ Available = [8,4,5,3] (P1 satisfied)

ALLOCATION MAX NEED AVAILBLE


A B C D A B C D A B C D A B C D
P0 3 2 1 1 9 5 5 3
P1 1 2 0 2
P2 1 0 1 0 3 2 1 0 2 2 0 0
P3 0 1 0 1 2 1 0 1 2 0 0 0

STEP:-3
P2’s Need = [2,2,0,0] ≤ Available = [9,5,5,3] (P2 satisfied)
B)

Yes the system in a safe state because there is no deadlock.

c) No there no deadlock because deadlock occurs in unsafe mode.

d)P3’s Request = [2,1,0,0]


P3’s Need = [2,0,0,0]
Since P3’s Request >= P3’s Need
Hence this request cannot be granted.

Potrebbero piacerti anche