0% found this document useful (0 votes)
50 views

Course: OS & USP Course Code: 21VMT0C104 Assignment: 1 Full Marks: 20 Name: Anoop Bose

The document contains the answers to 4 questions related to operating systems concepts. Question 1 provides the Gantt chart and calculations for process scheduling algorithms like SJF, RR, and SRTF. Question 2 discusses designing a multi-level scheduling scheme. Question 3 explains how to use semaphores to solve producer-consumer problems. Question 4 analyzes changes that can be safely made to the banker's algorithm for deadlock avoidance.

Uploaded by

Md Tausif Ansari
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Course: OS & USP Course Code: 21VMT0C104 Assignment: 1 Full Marks: 20 Name: Anoop Bose

The document contains the answers to 4 questions related to operating systems concepts. Question 1 provides the Gantt chart and calculations for process scheduling algorithms like SJF, RR, and SRTF. Question 2 discusses designing a multi-level scheduling scheme. Question 3 explains how to use semaphores to solve producer-consumer problems. Question 4 analyzes changes that can be safely made to the banker's algorithm for deadlock avoidance.

Uploaded by

Md Tausif Ansari
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Course: OS & USP

Course Code: 21VMT0C104


Assignment: 1
Full Marks: 20
Name: Anoop Bose
MCA – Artificial Intelligence

Subjective Section

Question 1:

Comparison of Non Pre-emptive SJF Scheduling, RR and Pre-emptive SRTF Algorithms. Given the
following mix of process, process burst time, and arrival time, compute the completion for each job
and average response time for the Non Pre-emptive SJF, RR, and Pre-emptive SRTF algorithms.
(Note: For RR assume a time quantum of 10 seconds)

Answer:

Arrival Burst Finish Turnaround Waiting


Job Time Time Time Time Time
A 0 85 220 220 135
B 10 30 80 70 40
C 10 35 125 115 80
D 80 20 145 65 45
E 85 50 215 130 80

GANTT
CHART
A B C A B C A B C A D E
0 10 20 30 40 50 60 70 80 90 100 110
C A D E A E A E A E A
120 125 135 145 155 165 175 185 185 195 205 215 220

Question 2:

As a system administrator you have noticed that usage peaks between 10:00AM to 5:00PM and
between 7:00PM to 10:00PM. The company's CEO decided to call on you to design a system where
during these peak hours there will be three levels of users. Users in level 1 are to enjoy better
response time than users in level 2, who in turn will enjoy better response time than users in level 3.
You are to design such a system so that all users will still get some progress, but with the indicated
preferences in place. Design a scheduling scheme that meets the requirements?

Answer:

A fixed priority scheme can cause starvation. The required solution should enable all users to make
progress. Fixed priority can not guarantee progress for processes with low priorities.
We also note that a multi feedback queuing system will cause processes in level 1 to get less time of
CPU if they stay in the system for very long. So, even if a level 1 process may start at the highest level
in the feedback queue, its priority will degrade over time.

A process of level-1 will have 3 entries in the ready queue, distributed evenly over the queue. A
process of level-2 will have 2 entries while a process of level 3 will have one entry. In a run, a process
at level 1 will get 3 times as much as a process at level 3 on the CPU. Care should be taken such that
when a process requests an I/O operation, that all its entries would be removed from the ready
queue simultaneously. Also, when a process is added to the ready queue, it must be entered with all
its entries evenly distributed over the entire queue. Other solutions such as a lottery scheduler are
also possible.

Question 3:

There is one Producer in the producer-consumer problem, Producer is producing some items,
whereas there is one Consumer that is consuming the items produced by the Producer. The same
memory buffer is shared by both producers and consumers which is of fixed-size. The following
problems occur in this scenario:

a) The producer should produce data only when the buffer is not full. In case it is found that the
buffer is full, the producer is not allowed to store any data into the memory buffer.

b) Data can only be consumed by the consumer if and only if the memory buffer is not empty. In
case it is found that the buffer is empty, the consumer is not allowed to use any data from the
memory buffer.

c) Accessing memory buffer should not be allowed to producer and consumer at the same time.

How can you use semaphores to solve each of the above mentioned problems? Explain.

Answer:

In the producer-consumer problem, we use three semaphore variables:

1. Semaphore S: This semaphore variable is used to achieve mutual exclusion between


processes. By using this variable, either Producer or Consumer will be allowed to use or
access the shared buffer at a particular time. This variable is set to 1 initially.

2. Semaphore E: This semaphore variable is used to define the empty space in the buffer.
Initially, it is set to the whole space of the buffer i.e. "n" because the buffer is initially empty.

3. Semaphore F: This semaphore variable is used to define the space that is filled by the
producer. Initially, it is set to "0" because there is no space filled by the producer initially.

By using the above three semaphore variables and by using the wait() and signal() function, we can
solve our problem(the wait() function decreases the semaphore variable by 1 and
the signal() function increases the semaphore variable by 1). So. let's see how.

The following is the pseudo-code for the producer:

void producer()
{
while(T) {
produce()
wait(E)
wait(S)
append()
signal(S)
signal(F)
}
}
The above code can be summarized as:

• while() is used to produce data, again and again, if it wishes to produce, again and again.

• produce() function is called to produce data by the producer.

• wait(E) will reduce the value of the semaphore variable "E" by one i.e. when the producer
produces something then there is a decrease in the value of the empty space in the buffer. If
the buffer is full i.e. the vale of the semaphore variable "E" is "0", then the program will stop
its execution and no production will be done.

• wait(S) is used to set the semaphore variable "S" to "0" so that no other process can enter
into the critical section.

• append() function is used to append the newly produced data in the buffer.

• signal(s) is used to set the semaphore variable "S" to "1" so that other processes can come
into the critical section now because the production is done and the append operation is
also done.

• signal(F) is used to increase the semaphore variable "F" by one because after adding the
data into the buffer, one space is filled in the buffer and the variable "F" must be updated.

This is how we solve the produce part of the producer-consumer problem. Now, let's see the
consumer solution. The following is the code for the consumer:

void consumer()
{
while(T) {
wait(F)
wait(S)
take()
signal(S)
signal(E)
use()
}
}

The above code can be summarized as:

• while() is used to consume data, again and again, if it wishes to consume, again and again.

• wait(F) is used to decrease the semaphore variable "F" by one because if some data is
consumed by the consumer then the variable "F" must be decreased by one.
• wait(S) is used to set the semaphore variable "S" to "0" so that no other process can enter
into the critical section.

• take() function is used to take the data from the buffer by the consumer.

• signal(S) is used to set the semaphore variable "S" to "1" so that other processes can come
into the critical section now because the consumption is done and the take operation is also
done.

• signal(E) is used to increase the semaphore variable "E" by one because after taking the data
from the buffer, one space is freed from the buffer and the variable "E" must be increased.

• use() is a function that is used to use the data taken from the buffer by the process to do
some operation.

Question 4:

On a real computer system, neither the resources available nor the demands of processes for
resources are consistent over long periods (months). Resources break or are replaced, new
processes come and go, new resources are bought and added to the system. If deadlock is controlled
by the banker's algorithm, which of the following changes can be made safely (without introducing
the possibility of deadlock), and under what circumstances?

a) Increase Available (new resources added).

b) Decrease, Available (resource permanently removed from system).

c) Increase Max for one process (the process needs more resources than allowed; it may want
more).

d) Decrease Max for one process (the process decides it does not need that many resources).

e) Increase the number of processes.

f) Decrease the number of processes.

Answer:

a. This can safely be changed without any problems.


b. This can influence the system and introduce the possibility of a deadlock as the safety of the
system assumes that there are a certain number of available resources.
c. This could influence the system and introduce the possibility of deadlock.
d. This could safely be changed without any problems.
e. This could be allowed assuming that resources were allocated to the new process(es) such
that the system does not enter an unsafe state.
f. This could safely be changed without any problems.

You might also like