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

Operating System Solutions

The document contains 20 multiple choice questions about operating system concepts like semaphores, deadlocks, scheduling, and processes. Semaphores are used for synchronization (question 1). Preemptive priority scheduling is used to determine the finish times of processes with different arrival times, priorities, and CPU/I/O burst durations (question 6). Improper usage of semaphore operations can lead to deadlock, and semaphores alone do not guarantee progress (questions 17). Four binary semaphores are needed to avoid deadlock when two processes access four shared resources with specific scheduling constraints (question 18).

Uploaded by

ergrehge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views

Operating System Solutions

The document contains 20 multiple choice questions about operating system concepts like semaphores, deadlocks, scheduling, and processes. Semaphores are used for synchronization (question 1). Preemptive priority scheduling is used to determine the finish times of processes with different arrival times, priorities, and CPU/I/O burst durations (question 6). Improper usage of semaphore operations can lead to deadlock, and semaphores alone do not guarantee progress (questions 17). Four binary semaphores are needed to avoid deadlock when two processes access four shared resources with specific scheduling constraints (question 18).

Uploaded by

ergrehge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

OPERATING SYSTEM

Solutions
1. Semaphore is used for:

(a) Synchronization (b) Deadlock Avoidance


(c) Bounded Waiting (d) None

Solution: Option (a)

2. Assume that ‘C’ is a Counting Semaphore initialized to value ‘10’. Consider the following
program segment:

P(C); V(C); P(C); P(C); P(C); V(C); V(C)


V(C); V(C); V(C); P(C); V(C); V(C); P(C)

What is the value of C?


(a) 6 (b) 12
(c) 8 (d) 10

Solution: Option (b)

3. Which of the following is not a valid deadlock prevention scheme?

(a) Release all resources before requesting a new resource


(b) Number the resources uniquely and never request a
resource with a lower number than last requested
(c) Never request a resource after releasing any resource
(d) Request all required resources before execution

Solution: Option (c)

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:

What should be written at W to avoid deadlock?


(a) P(T) (b) P(U)
(c) P(S) (d) Not possible to avoid deadlock

Solution: Option (a)

5. What should be written at X and Y for the above problem?

(a) P(S), P(T) (b) P(T), P(U)


(c) P(S), P(U) (d) None

Solution: Option (b)

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.

Process AT Priority Burst duration


CPU, I/O, CPU
P1 0 2 1, 5, 3
P2 2 3 (lowest) 3, 3, 1
P3 3 1 (highest) 2, 3, 1

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

Solution: Option (c)

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.

Which of the following is true?


(a) The process can deadlock
(b) One of the threads can starve
(c) Some items produced may be lost
(d) None of the above

Solution: Option (d)

8. Readers-Writers problem can be solved using:

(a) Semaphores (b) Monitors


(c) Both (a) & (b) (d) None

Solution: Option (c)

9. Consider the following pseudo code fragment:

Printf (“Hello”);
if(!fork( ))
Printf(“World”);

Which of the following is the output of the code fragment?


(a) Hello Hello World World (b) Hello World World
(c) Hello World (d) Hello World Hello World

Solution: Option (c)

10. Which of the following is initiated by process itself?

(a) Running (b) Ready


(c) Suspend (d) Block

3
Solution: Option (d)

11. Consider the following program:

main( )
{
intpid
pid= fork( );
printf(“%d”, pid);
}

What is the output by parent and child processes?


(a) child= 0, parent= 0 (b) child= 0, parent= process_id of child
(c) child= 1, parent= 0 (d) none

Solution: Option (b)

12. A CPU generally handles an interrupt by executing an interrupt service routine:

(a) as soon as an interrupt is raised


(b) by checking the interrupt register at the end of fetch cycle
(c) by checking the interrupt register after finishing the execution of the current instruction
(d) none of the above

Solution: Option (c)

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?

(a) This algorithm is equivalent to FCFS


(b) This algorithm is equivalent to Round Robbin
(c) This algorithm is equivalent to SJF
(d) This algorithm is equivalent to Shortest Remaining Time First

Solution: Option (b)

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

Solution: Option (d)

15. Which of the following instructions should be allowed only in Kernel Mode?

(a) Disable all interrupts (b) Read the time-of-day clock


(c) Set the time-of-day clock (d) Change the Memory Map

Solution: Option (a)

16. Consider the below code fragment:

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

Solution: Option (a)

17. Which of the following regarding semaphores are true?

(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:

P1: Compute; P2: Compute;


Use R1; Use R1;
Use R2; Use R2;
Use R3; Use R3;
Use R4; Use R4;

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:

P2 must complete use of R1 before P1 gets access to R1


P1 must complete use of R2 before P2 gets access to R2
P2 must complete use of R3 before P1 gets access to R3
P1 must complete use of R4 before P2 gets access to R4

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

Solution: Option (d)

19. Consider the program segment:

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

(a) 1 only (b) 1 & 2 only


(c) 1 & 3 only (d) 2 & 3 only
(e) 1, 2, 3

Solution: Option (d)

20. Which of the following is not a necessary condition for a deadlock among processes?

(a) Shared Resources (b) No Preemption


(c) Acyclic condition among processes (d) None of the above

Solution: Option (d)

You might also like