Course: OS & USP Course Code: 21VMT0C104 Assignment: 1 Full Marks: 20 Name: Anoop Bose
Course: OS & USP Course Code: 21VMT0C104 Assignment: 1 Full Marks: 20 Name: Anoop Bose
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:
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:
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.
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.
• 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()
}
}
• 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?
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).
Answer: