Operating System Questions and Answers - The Critical Section (CS) Problem and Solutions
Operating System Questions and Answers - The Critical Section (CS) Problem and Solutions
Solutions
This set of Operating System Multiple Choice Questions & Answers (MCQs) focuses on
“The Critical Section (CS) Problem and Solutions”.
This set of Operating System Multiple Choice Questions & Answers (MCQs) focuses on
“Semaphores”.
Process P1
wait(S1);
release(S0);
Process P2
wait(S2);
release(S0);
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)?
a) 1
b) 2
c) 3
d) None of the mentioned
View Answer
Answer: c
Explanation: Any one of the 9 processes can get into critical section after executing
P(mutex) which decrements the mutex value to 0. At this time P10 can enter critical
section by incrementing the value to 1. Now any of the 9 processes can enter the critical
section by again decrementing the mutex value to 0. None of the remaining processes
can get into their critical sections.
13. 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 have shared variables, which are initialized to false. Which one of the
following statements is TRUE about the above construct?
a) It does not ensure mutual exclusion
b) It does not ensure bounded waiting
c) It requires that processes enter the critical section in strict alternation
d) It does not prevent deadlocks but ensures mutual exclusion
View Answer
Answer: d
Explanation: None.
This set of Operating System Interview Questions and Answers for freshers focuses on
“Semaphores – 2” and will also be useful for interview preparations for freshers.
1. What will happen if a non-recursive mutex is locked more than once?
a) Starvation
b) Deadlock
c) Aging
d) Signaling
View Answer
Answer: b
Explanation: If a thread which had already locked a mutex, tries to lock the mutex again,
it will enter into the waiting list of that mutex, which results in a deadlock. It is because
no other thread can unlock the mutex.
2. What is a semaphore?
a) is a binary mutex
b) must be accessed from only one process
c) can be accessed from multiple processes
d) none of the mentioned
View Answer
Answer: c
Explanation: None.
3. What are the two kinds of semaphores?
a) mutex & counting
b) binary & counting
c) counting & decimal
d) decimal & binary
View Answer
Answer: b
Explanation: None.
4. What is a mutex?
a) is a binary mutex
b) must be accessed from only one process
c) can be accessed from multiple processes
d) none of the mentioned
View Answer
Answer: b
Explanation: None.
5. At a particular time of computation the value of a counting semaphore is 7.Then 20 P
operations and 15 V operations were completed on this semaphore. The resulting value
of the semaphore is? (GATE 1987)
a) 42
b) 2
c) 7
d) 12
View Answer
Answer: b
Explanation: P represents Wait and V represents Signal. P operation will decrease the
value by 1 every time and V operation will increase the value by 1 every time.
6. A binary semaphore is a semaphore with integer values ____________
a) 1
b) -1
c) 0.8
d) 0.5
View Answer
Answer: a
Explanation: None.
7. The following pair of processes share a common variable X.
Process A
int Y;
A1: Y = X*2;
A2: X = Y;
Process B
int Z;
B1: Z = X+1;
B2: X = Z;
Process B
int Z;
B1: wait(T);
B2: Z = X+1;
X = Z;
This set of 1000+ Operating System MCQs focuses on “The Classic Synchronization
Problems”
In this situation :
a) a deadlock will occur
b) processes will starve to enter critical section
c) several processes maybe executing in their critical section
d) all of the mentioned
View Answer
Answer: c
Explanation: None.
8. All processes share a semaphore variable mutex, initialized to 1. Each process must
execute wait(mutex) before entering the critical section and signal(mutex) afterward.
Suppose a process executes in the following manner.
wait(mutex);
.....
critical section
.....
wait(mutex);
9. Consider the methods used by processes P1 and P2 for accessing their critical
sections whenever needed, as given below. The initial values of shared boolean
variables S1 and S2 are randomly assigned. (GATE 2010)
Method used by P1 :
while(S1==S2);
Critical section
S1 = S2;
Method used by P2 :
while(S1!=S2);
Critical section
S2 = not(S1);
This set of Operating System Multiple Choice Questions & Answers (MCQs) focuses on
“Monitors”.
This set of Operating System Multiple Choice Questions & Answers (MCQs) focuses on
“Atomic Transactions”.