Tutorial Problems

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1. Consider a system with 5 processes P0, P1, P2, P3, and P4 with 3 resources A,B, and C.

Resource A has 10, B has 5 and C has 7 instances. The maximum and allocation matrices
are as follows:
                         A        B         C                                 A         B         C
             P0       7          5          3                                  0          1          0
             P1       3          2          2                                  2          0          0
             P2       9          0          2                                  3          0          2
            P3        2          2          2                                  2          1          1
            P4        4          3          3                                  0          0          2
 
                                 MAX                                         ALLOCATION
 
 
i) Is the present state safe? If so, give the sequence.
ii) If P1 is requesting for[ 1 0 2], can the request be granted?
iii) If P4 is requesting for [ 3 3 0], can the request be granted?
iv) If P0 is requesting for [0 2 0], can the request be granted?
 
2. Consider the following snapshot of a system
                             Allocation            Max                     Available
                             A   B   C   D               A   B   C   D               A   B   C   D
                           P0   0    0    1   2                   0    0    1    2                1    5    2   0
                           P1   1    0    0  0                    1    7    5    0               
                           P2   1    3    5   4                   2    3    5    6               
                           P3   0    6    3   2                   0    6    5    2               
                           P4   0    0    1   4                   0    6    5    6               
 
           Answer the following questions using Banker’s algorithm
              i. What is the content of matrix Need?
              ii. Is the system in a safe state?
              iii. If a request from process P1 arrives for (0, 4, 2, 0), can the request be granted
immediately?

3. The following program consists of 3 concurrent processes and 3 binary semaphores. The
semaphores are initialized as S0 = 1, S1 = 0, S2 = 0.
Process P0
while(true)
{
wait(S0);
print ‘0’;
release(S1);
release(S2);
}
Process P1
wait(S1);
release(S0);

Process P2
wait(S2);
release(S0);

How many times will P0 print ‘0’ ?

Each process Pi, i = 0,1,2,3,……,9 is coded as follows :


repeat
P(mutex)
{Critical Section}
V(mutex)
forever
The code for P10 is identical except that it uses V(mutex) instead of P(mutex). What is the largest
number of processes that can be inside the critical section at any moment (the mutex being initialized to
1)?

4. Two processes, P1 and P2, need to access a critical section of code. Consider the
following synchronization construct used by the processes :
Process P1 :
while(true)
{
w1 = true;
while(w2 == true);
Critical section
w1 = false;
}
Remainder Section

Process P2 :
while(true)
{
w2 = true;
while(w1 == true);
Critical section
w2 = false;
}
Remainder Section
Here, w1 and w2 are shared variables, which are initialized to false. Which one of the following
statements is TRUE about the above construct?

5. A system has 12 magnetic tape drives and 3 processes : P0, P1, and P2. Process P0 requires
10 tape drives, P1 requires 4 and P2 requires 9 tape drives.
Process
P0
P1
P2
Maximum needs (process-wise : P0 through P2 top to bottom)
10
4
9
Currently allocated (process-wise)
5
2
2
Which of the following sequence is a safe sequence ?
6. Suppose that a disk drive has 5,000 cylinders, numbered 0 to 4999. The drive is currently
serving a request at cylinder 143, and the previous request was at cylinder 125. The
queue of pending requests, in FIFO order is:
                          86, 1470,913, 1774, 948, 1509, 1022, 1750, 130
           Starting from the current head position, what is the total distance (in cylinders) that the
disk arm moves to satisfy all the pending requests for each of the following Disk Scheduling
algorithms?

                 a) FCFS           b) SSTF     


7. Suppose that a disk drive has 5,000 cylinders, numbered 0 to 4999. The drive is currently
serving a request at cylinder 143, and the previous request was at cylinder 125. The
queue of pending requests, in FIFO order is:
                          86, 1470,913, 1774, 948, 1509, 1022, 1750, 130
           Starting from the current head position, what is the total distance (in cylinders) that the
disk arm moves to satisfy all the pending requests for each of the following Disk Scheduling
algorithms?

a) SCAN         b) C-SCAN   
8. Suppose that a disk drive has 5,000 cylinders, numbered 0 to 4999. The drive is currently
serving a request at cylinder 143, and the previous request was at cylinder 125. The queue of
pending requests, in FIFO order is:
                          86, 1470,913, 1774, 948, 1509, 1022, 1750, 130
           Starting from the current head position, what is the total distance (in cylinders) that the
disk arm moves to satisfy all the pending requests for each of the following Disk Scheduling
algorithms?

                        a) LOOK         b) C-LOOK

You might also like