Operating System Solutions
Operating System Solutions
Solutions
1. Semaphore is used for:
2. Assume that ‘C’ is a Counting Semaphore initialized to value ‘10’. Consider the following
program segment:
4. Suppose we want to synchronize two concurrent processes P and Q using binary semaphores
S, T and U:
Process P: Process Q:
P(S) W:
P(T) X:
1
P(U) Y:
Print ‘a’ Print ‘a’;
Print ‘b’ Print ‘b’;
V(S) A:
V(T) B:
V(U) C:
6. The arrival time, priority and durations of the CPU and I/O bursts for each of the three
processes P1, P2 and P3 are given in the table below. Each process has a CPU burst followed by
an I/O burst followed by another CPU burst. Assume that each process has its own I/O resource.
If the Preemptive priority scheduling is used, what is the finish times of the processes?
(a) 11, 15, 9 (b) 10, 15, 9
(c) 11, 16, 10 (d) 12, 17, 11
7. The following code with two threads can run in parallel. S and Q are binary semaphores
equipped with P & V operations.
2
S= 1 & Q= 0;
Producer: Consumer:
while (true) do while (true) do
P(S); P(Q);
x= Produce( ); Consume(x);
V(Q) V(S)
done done.
Printf (“Hello”);
if(!fork( ))
Printf(“World”);
3
Solution: Option (d)
main( )
{
intpid
pid= fork( );
printf(“%d”, pid);
}
13. A scheduling algorithm assigns priority proportional to the waiting time of a process. Every
process starts with priority zero (the lowest). The scheduler re-valuates the process priorities
every T time units and decides the next process to schedule. Which one of the following is true if
the processes have no I/O operations and all arrive at time zero?
4
14. The highest response ratio next Scheduling policy favors ‘X’ jobs, but is also limits the
waiting time of ‘Y’ jobs. What are X and Y?
(a) Shorter Jobs, Low Priority Jobs (b) Longer Jobs, High Priority Jobs
(c) Longer Jobs, Shorter Jobs (d) Shorter Jobs, Longer Jobs
15. Which of the following instructions should be allowed only in Kernel Mode?
if(fork k( ) = = 0)
{
a= a+5; printf(“%d, %d \n”, a, &a);
}
else
{
a= a – 5;
printf(“%d %d \n”, 0, &a);
}
Let u, v be the values printed by parent process and x, y be the values printed by child process.
Which one of the following is true?
(a) u= x + 10 and v = y (b) u= x + 10 and v≠ y
(c) u + 10= x and v = y (d) u + 10= x and v ≠ y
(a) Semaphores always guarantee Mutual Exclusion but fail to guarantee progress
(b) Under certain situations may fail to guarantee Mutual exclusion
(c) Improper usage of semaphore operations may lead to deadlock
(d) Both (a) & (c) are true
5
Solution: Option (d)
18. Two concurrent processes P1 and P2use four shared resources R1, R2, R3 and R4 as shown
below:
Both processes are started at the same time, and each resource can be accessed by only one
process at a time. The following scheduling constraints exist between the accesses of resources
by the processes:
There are no other scheduling constraints between the processes above scheduling constraints,
what is the minimum no. of binary semaphores needed?
(a) 1 (b) 2
(c) 3 (d) 4
x= 0; y=0;
Cobegin
begin
x= 1;
y= y + x;
end
begin
y= 2;
x= x + 3;
end
Coend;
6
Which of the following indicates possible values for the variables when the segment finishes
execution?
(1) x= 1, y= 2
(2) x= 1, y= 3
(3) x= 4, y= 6
20. Which of the following is not a necessary condition for a deadlock among processes?