OS Assignment
OS Assignment
ASSIGNMENT
10 MARKS(Each 2 marks)
1) Consider the following processes with arrival time and burst time. Calculate average turnaround time,
average waiting time and average response time using round robin with time quantum 3?
Ans:-
Queue.
P4 P5 P3 P2 P4 P1 P6 P3 P2 P4 P1 P3
Gantt Chart
P4 P5 P3 P2 P4 P1 P6 P3 P2 P4 P1 P3
1. 4. 6. 9. 12. 15. 18. 21. 24. 27. 30. 32. 33
2) An operating system uses the banker’s algorithm for deadlock avoidance when managing the allocation of three resource types
X, Y and Z to three processes P0, P1 and P2. The table given below presents the current system state. Here, the Allocation matrix
shows the current number of resources of each type allocated to each process and the Max matrix shows the maximum number of
resources of each type required by each process during its execution. There are 3 units of type X, 2 units of type Y and 2 units of
type Z still available. The system is currently in safe state. Consider the following independent requests for additional resources in
the current state-
REQ1: P0 requests 0 units of X, 0 units of Y and 2 units of Z. Can this request be processed as per the Bankers algorithm and find
out if a safe state can be achieved after its execution.
Max
Allocation
X Y Z X Y Z
P0 0 0 1 8 4 3
P1 3 2 0 6 2 0
P2 2 1 1 3 3 3
MAX ALLOCATION
XYZ XYZ
P0 843 001
P1 620 320
P2 333 211
Now, with the current availability, we can service the need of P1. The state would become :
Ans:- If C.P.U and I/O devices are nearly same at speed, the buffering helps in making the C.P.U and the I/O devices work at full speed in such
a way that C.P.U and the I/O devices never sit idle at any moment. Normally the C.P.U is much faster than an input device. In this case the C.P.U
always faces an empty input buffer and sits idle waiting for the input device which is to read a record into the buffer. For output, the C.P.U
continues to work at full speed till the output buffer is full and then it starts waiting. Thus buffering proves useful for those jobs that have a balance
between computational work and I/O operations. In other cases, buffering scheme may not work well. Buffering matches the speed between the
sender and receiver of the data stream. Buffer stores the original copy of data. Buffer is an area in primary memory (RAM).
1. Binary Semaphore – This is also known as mutex lock. It can have only two values – 0 and 1. Its value is initialized to 1. It is used to implement
the solution of critical section problem with multiple processes.
2. Counting Semaphore – Its value can range over an unrestricted domain. It is used to control access to a resource that has multiple instances.
1. First, look at two operations which can be used to access and change the value of the semaphore variable. P operation is also called wait, sleep or
down operation and V operation is also called signal, wake-up or up operation.
2. Both operations are atomic and semaphore(s) is always initialized to one. Here atomic means that variable on which read, modify and update
happens at the same time/moment with no pre-emption i.e. in between read, modify and update no other operation is performed that may change the
variable.
3. A critical section is surrounded by both operations to implement process synchronization.
Now, let us see how it implements mutual exclusion. Let there be two processes P1 and P2 and a semaphore s is initialized as 1. Now if suppose P1 enters
in its critical section then the value of semaphore s becomes 0. Now if P2 wants to enter its critical section then it will wait until s > 0, this can only happen
when P1 finishes its critical section and calls V operation on semaphore s. This way mutual exclusion is achieved.