Process Synchroniza on
This set of Opera ng System Mul ple Choice Ques ons & Answers (MCQs) focuses on “The Cri cal
Sec on (CS) Problem and Solu ons”.
1. Concurrent access to shared data may result in ____________
a) data consistency
b) data insecurity
c) data inconsistency
d) none of the men oned
Answer: c
Explana on: None.
2. A situa on where several processes access and manipulate the same data concurrently and the
outcome of the execu on depends on the par cular order in which access takes place is called
____________
a) data consistency
b) race condi on
c) aging
d) starva on
View Answer
Answer: b
Explana on: None.
3. The segment of code in which the process may change common variables, update tables, write
into files is known as ____________
a) program
b) cri cal sec on
c) non – cri cal sec on
d) synchronizing
View Answer
Answer: b
Explana on: None.
4. Which of the following condi ons must be sa sfied to solve the cri cal sec on problem?
a) Mutual Exclusion
b) Progress
c) Bounded Wai ng
d) All of the men oned
View Answer
Answer: d
Explana on: None.
5. Mutual exclusion implies that ____________
a) if a process is execu ng in its cri cal sec on, then no other process must be execu ng in their
cri cal sec ons
b) if a process is execu ng in its cri cal sec on, then other processes must be execu ng in their
cri cal sec ons
c) if a process is execu ng in its cri cal sec on, then all the resources of the system must be blocked
un l it finishes execu on
d) none of the men oned
View Answer
Answer: a
Explana on: None.
Note: Join free Sanfoundry classes at Telegram or Youtube
6. Bounded wai ng implies that there exists a bound on the number of mes a process is allowed to
enter its cri cal sec on ____________
a) a er a process has made a request to enter its cri cal sec on and before the request is granted
b) when another process is in its cri cal sec on
c) before a process has made a request to enter its cri cal sec on
d) none of the men oned
View Answer
Answer: a
Explana on: None.
7. A minimum of _____ variable(s) is/are required to be shared between processes to solve the
cri cal sec on problem.
a) one
b) two
c) three
d) four
View Answer
Answer: b
Explana on: None.
8. In the bakery algorithm to solve the cri cal sec on problem ____________
a) each process is put into a queue and picked up in an ordered manner
b) each process receives a number (may or may not be unique) and the one with the lowest number
is served next
c) each process gets a unique number and the one with the highest number is served next
d) each process gets a unique number and the one with the lowest number is served next
View Answer
Answer: b
Explana on: None.
This set of Opera ng System Mul ple Choice Ques ons & Answers (MCQs) focuses on
“Semaphores”.
1. An un-interrup ble unit is known as ____________
a) single
b) atomic
c) sta c
d) none of the men oned
View Answer
Answer: b
Explana on: None.
2. TestAndSet instruc on is executed ____________
a) a er a par cular process
b) periodically
c) atomically
d) none of the men oned
View Answer
Answer: c
Explana on: None.
3. Semaphore is a/an _______ to solve the cri cal sec on problem.
a) hardware for a system
b) special program for a system
c) integer variable
d) none of the men oned
View Answer
Answer: c
Explana on: None.
4. What are the two atomic opera ons permissible on semaphores?
a) wait and signal
b) stop and wait
c) hold and signal
d) none of the men oned
View Answer
Answer: a
Explana on: None.
5. What are Spinlocks?
a) CPU cycles was ng locks over cri cal sec ons of programs
b) Locks that avoid me wastage in context switches
c) Locks that work be er on mul processor systems
d) All of the men oned
View Answer
Answer: d
Explana on: None.
Sanfoundry Cer fica on Contest of the Month is Live. 100+ Subjects. Par cipate Now!
6. What is the main disadvantage of spinlocks?
a) they are not sufficient for many process
b) they require busy wai ng
c) they are unreliable some mes
d) they are too complex for programmers
View Answer
Answer: b
Explana on: None.
7. The wait opera on of the semaphore basically works on the basic _______ system call.
a) stop()
b) block()
c) hold()
d) wait()
View Answer
Answer: b
Explana on: None.
8. The signal opera on of the semaphore basically works on the basic _______ system call.
a) con nue()
b) wakeup()
c) getup()
d) start()
View Answer
Answer: b
Explana on: None.
9. If the semaphore value is nega ve ____________
a) its magnitude is the number of processes wai ng on that semaphore
b) it is invalid
c) no opera on can be further performed on it un l the signal opera on is performed on it
d) none of the men oned
View Answer
Answer: a
Explana on: None.
10. The code that changes the value of the semaphore is ____________
a) remainder sec on code
b) non – cri cal sec on code
c) cri cal sec on code
d) none of the men oned
View Answer
Answer: c
Explana on: None.
11. The following program consists of 3 concurrent processes and 3 binary semaphores. The
semaphores are ini alized 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 mes will P0 print ‘0’?
a) At least twice
b) Exactly twice
c) Exactly thrice
d) Exactly once
View Answer
Answer: a
Explana on: None.
12. Each process Pi, i = 0,1,2,3,……,9 is coded as follows.
repeat
P(mutex)
{Cri cal Sec on}
V(mutex)
forever
The code for P10 is iden cal except that it uses V(mutex) instead of P(mutex). What is the largest
number of processes that can be inside the cri cal sec on at any moment (the mutex being
ini alized to 1)?
a) 1
b) 2
c) 3
d) None of the men oned
View Answer
Answer: c
Explana on: Any one of the 9 processes can get into cri cal sec on a er execu ng P(mutex) which
decrements the mutex value to 0. At this me P10 can enter cri cal sec on by incremen ng the
value to 1. Now any of the 9 processes can enter the cri cal sec on by again decremen ng the
mutex value to 0. None of the remaining processes can get into their cri cal sec ons.
13. Two processes, P1 and P2, need to access a cri cal sec on of code. Consider the following
synchroniza on construct used by the processes.
Process P1 :
while(true)
w1 = true;
while(w2 == true);
Cri cal sec on
w1 = false;
Remainder Sec on
Process P2 :
while(true)
w2 = true;
while(w1 == true);
Cri cal sec on
w2 = false;
Remainder Sec on
Here, w1 and w2 have shared variables, which are ini alized 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 wai ng
c) It requires that processes enter the cri cal sec on in strict alterna on
d) It does not prevent deadlocks but ensures mutual exclusion
View Answer
Answer: d
Explana on: None.
This set of Opera ng System Mul ple Choice Ques ons & Answers (MCQs) focuses on “Semaphores
– 2”.
1. What will happen if a non-recursive mutex is locked more than once?
a) Starva on
b) Deadlock
c) Aging
d) Signaling
View Answer
Answer: b
Explana on: If a thread which had already locked a mutex, tries to lock the mutex again, it will enter
into the wai ng 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 mul ple processes
d) none of the men oned
View Answer
Answer: c
Explana on: None.
3. What are the two kinds of semaphores?
a) mutex & coun ng
b) binary & coun ng
c) coun ng & decimal
d) decimal & binary
View Answer
Answer: b
Explana on: None.
4. What is a mutex?
a) is a binary mutex
b) must be accessed from only one process
c) can be accessed from mul ple processes
d) none of the men oned
View Answer
Answer: b
Explana on: None.
5. At a par cular me of computa on the value of a coun ng semaphore is [Link] 20 P opera ons
and 15 V opera ons were completed on this semaphore. The resul ng value of the semaphore is?
(GATE 1987)
a) 42
b) 2
c) 7
d) 12
View Answer
Answer: b
Explana on: P represents Wait and V represents Signal. P opera on will decrease the value by 1
every me and V opera on will increase the value by 1 every me.
Subscribe Now: Opera ng System Newsle er | Important Subjects Newsle ers
6. A binary semaphore is a semaphore with integer values ____________
a) 1
b) -1
c) 0.8
d) 0.5
View Answer
Answer: a
Explana on: 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;
X is set to 5 before either process begins execu on. As usual, statements within a process are
executed sequen ally, but statements in process A may execute in any order with respect to
statements in process B.
How many different values of X are possible a er both processes finish execu ng?
a) two
b) three
c) four
d) eightAnswer: c
Explana on: Here are the possible ways in which statements from A and B can be interleaved.
A1 A2 B1 B2: X = 11
A1 B1 A2 B2: X = 6
A1 B1 B2 A2: X = 10
B1 A1 B2 A2: X = 10
B1 A1 A2 B2: X = 6
B1 B2 A1 A2: X = 12.
8. The program follows to use a shared binary semaphore T.
Process A
int Y;
A1: Y = X*2;
A2: X = Y;
signal(T);
Process B
int Z;
B1: wait(T);
B2: Z = X+1;
X = Z;
T is set to 0 before either process begins execu on and, as before, X is set to 5.
Now, how many different values of X are possible a er both processes finish execu ng?
a) one
b) two
c) three
d) four
View Answer
Answer: a
Explana on: The semaphore T ensures that all the statements from A finish execu on before B
begins. So now there is only one way in which statements from A and B can be interleaved:
A1 A2 B1 B2: X = 11.
9. Semaphores are mostly used to implement ____________
a) System calls
b) IPC mechanisms
c) System protec on
d) None of the men oned
View Answer
Answer: b
Explana on: None.
10. Spinlocks are intended to provide __________ only.
a) Mutual Exclusion
b) Bounded Wai ng
c) Aging
d) Progress
Answer: b
This set of 1000+ Opera ng System MCQs focuses on “The Classic Synchroniza on Problems”
1. The bounded buffer problem is also known as ____________
a) Readers – Writers problem
b) Dining – Philosophers problem
c) Producer – Consumer problem
d) None of the men oned
View Answer
Answer: c
Explana on: None.
2. In the bounded buffer problem, there are the empty and full semaphores that ____________
a) count the number of empty and full buffers
b) count the number of empty and full memory spaces
c) count the number of empty and full queues
d) none of the men oned
View Answer
Answer: a
Explana on: None.
3. In the bounded buffer problem ____________
a) there is only one buffer
b) there are n buffers ( n being greater than one but finite)
c) there are infinite buffers
d) the buffer size is bounded
View Answer
Answer: b
Explana on: None.
4. To ensure difficul es do not arise in the readers – writers problem _______ are given exclusive
access to the shared object.
a) readers
b) writers
c) readers and writers
d) none of the men oned
View Answer
Answer: b
Explana on: None.
5. The dining – philosophers problem will occur in case of ____________
a) 5 philosophers and 5 chops cks
b) 4 philosophers and 5 chops cks
c) 3 philosophers and 5 chops cks
d) 6 philosophers and 5 chops cks
View Answer
Answer: a
Explana on: None.
Subscribe Now: Opera ng System Newsle er | Important Subjects Newsle ers
6. A deadlock free solu on to the dining philosophers problem ____________
a) necessarily eliminates the possibility of starva on
b) does not necessarily eliminate the possibility of starva on
c) eliminates any possibility of any kind of problem further
d) none of the men oned
View Answer
Answer: b
Explana on: None.
7. All processes share a semaphore variable mutex, ini alized to 1. Each process must execute
wait(mutex) before entering the cri cal sec on and signal(mutex) a erward.
Suppose a process executes in the following manner.
signal(mutex);
.....
cri cal sec on
.....
wait(mutex);
In this situa on :
a) a deadlock will occur
b) processes will starve to enter cri cal sec on
c) several processes maybe execu ng in their cri cal sec on
d) all of the men oned
View Answer
Answer: c
Explana on: None.
8. All processes share a semaphore variable mutex, ini alized to 1. Each process must execute
wait(mutex) before entering the cri cal sec on and signal(mutex) a erward.
Suppose a process executes in the following manner.
wait(mutex);
.....
cri cal sec on
.....
wait(mutex);
a) a deadlock will occur
b) processes will starve to enter cri cal sec on
c) several processes maybe execu ng in their cri cal sec on
d) all of the men oned
View Answer
Answer: a
Explana on: None.
9. Consider the methods used by processes P1 and P2 for accessing their cri cal sec ons whenever
needed, as given below. The ini al values of shared boolean variables S1 and S2 are randomly
assigned. (GATE 2010)
Method used by P1 :
while(S1==S2);
Cri cal sec on
S1 = S2;
Method used by P2 :
while(S1!=S2);
Cri cal sec on
S2 = not(S1);
Which of the following statements describes proper es achieved?
a) Mutual exclusion but not progress
b) Progress but not mutual exclusion
c) Neither mutual exclusion nor progress
d) Both mutual exclusion and progress
View Answer
Answer: d
Explana on: The while(S1==S2) or while(S1!=S2) loops will work as a mutex. When either P1 or P2
enters the Cri cal sec on (CS), they will make sure to change the values of S1 or S2 upon exit from
the CS such that the other process enters the CS while that process waits on the mutex.
This set of Opera ng System Mul ple Choice Ques ons & Answers (MCQs) focuses on “Monitors”.
1. A monitor is a type of ____________
a) semaphore
b) low level synchroniza on construct
c) high level synchroniza on construct
d) none of the men oned
Answer: c
2. A monitor is characterized by ____________
a) a set of programmer defined operators
b) an iden fier
c) the number of variables in it
d) all of the men oned
Answer: a
Explana on: None.
3. A procedure defined within a ________ can access only those variables declared locally within the
_______ and its formal parameters.
a) process, semaphore
b) process, monitor
c) semaphore, semaphore
d) monitor, monitor
View Answer
Answer: d
Explana on: None.
4. The monitor construct ensures that ____________
a) only one process can be ac ve at a me within the monitor
b) n number of processes can be ac ve at a me within the monitor (n being greater than 1)
c) the queue has only one process in it at a me
d) all of the men oned
View Answer
Answer: a
Explana on: None.
5. What are the opera ons that can be invoked on a condi on variable?
a) wait & signal
b) hold & wait
c) signal & hold
d) con nue & signal
View Answer
Answer: a
Explana on: None.
Note: Join free Sanfoundry classes at Telegram or Youtube
6. Which is the process of invoking the wait opera on?
a) suspended un l another process invokes the signal opera on
b) wai ng for another process to complete before it can itself call the signal opera on
c) stopped un l the next process in the queue finishes execu on
d) none of the men oned
View Answer
Answer: a
Explana on: None.
7. If no process is suspended, the signal opera on ____________
a) puts the system into a deadlock state
b) suspends some default process execu on
c) nothing happens
d) the output is unpredictable
View Answer
Answer: c
Explana on: None
This set of Opera ng System Mul ple Choice Ques ons & Answers (MCQs) focuses on “Atomic
Transac ons”.
1. A collec on of instruc ons that performs a single logical func on is called ____________
a) transac on
b) opera on
c) func on
d) all of the men oned
View Answer
Answer: a
Explana on: None.
2. A terminated transac on that has completed its execu on successfully is ____________ otherwise
it is __________
a) commi ed, destroyed
b) aborted, destroyed
c) commi ed, aborted
d) none of the men oned
View Answer
Answer: c
Explana on: None.
3. The state of the data accessed by an aborted transac on must be restored to what it was just
before the transac on started execu ng. This restora on is known as ________ of transac on.
a) safety
b) protec on
c) roll – back
d) revert – back
View Answer
Answer: c
Explana on: None.
4. Write ahead logging is a way ____________
a) to ensure atomicity
b) to keep data consistent
c) that records data on stable storage
d) all of the men oned
View Answer
Answer: d
Explana on: None.
5. In the write ahead logging a _____________ is maintained.
a) a memory
b) a system
c) a disk
d) a log record
Answer: d