MODULE 3 | O.S.
| BCS303 |
IMPORTANT QUESTIONS |
@Express VTU 4 All
Created @February 4, 2026 9:26 PM
Subject code BCS303
[Link] [Link]/@expressvtu4all
si=0XDGsgF7HTRj6Gkw
QUES 1 : Define deadlock. What are the necessary
conditions for deadlock to occur?
Answer:
A deadlock is a situation in an operating system where two or more processes
are permanently blocked, and each process is waiting for a resource that is
held by another process in the set. Since none of the processes can proceed,
the system enters a deadlock state.
In a deadlock situation:
Processes hold one or more resources
Each process waits indefinitely for additional resources
No process can continue execution
Deadlocks usually occur in multiprogramming environments where multiple
processes compete for limited resources such as CPU, memory, files, or I/O
devices.
MODULE 3 | O.S. | BCS303 | IMPORTANT QUESTIONS | @Express VTU 4 All 1
This situation is called a deadlock .:
Necessary Conditions for Deadlock
For a deadlock to occur, all the following four conditions must hold
simultaneously. If any one condition is absent, deadlock cannot occur.
1. Mutual Exclusion
At least one resource must be held in a non-shareable mode.
This means only one process can use the resource at a time.
Example:
A printer can be used by only one process at a time.
2. Hold and Wait
A process must be holding at least one resource and waiting to acquire
additional resources that are currently held by other processes.
Example:
Process P1 holds resource R1 and waits for resource R2 held by P2.
3. No Preemption
Resources cannot be forcibly taken away from a process.
They must be released voluntarily after the process has completed its task.
Example:
MODULE 3 | O.S. | BCS303 | IMPORTANT QUESTIONS | @Express VTU 4 All 2
A process releases a file only after closing it.
4. Circular Wait
A set of processes must exist such that:
P1 waits for a resource held by P2
P2 waits for a resource held by P3
Pn waits for a resource held by P1
This forms a circular chain of waiting processes.
Example:
P1 → P2 → P3 → P1
QUES 2 : Explain different methods to recover from
deadlocks.
Answer:
When a deadlock occurs, the operating system must take action to recover the
system and allow blocked processes to continue execution. Deadlock
recovery involves breaking one or more of the deadlock conditions.
The two main approaches for deadlock recovery are:
1. Process Termination
2. Resource Preemption
1. Deadlock Recovery by Process Termination
In this method, the operating system terminates one or more processes
involved in the deadlock to break the circular wait.
MODULE 3 | O.S. | BCS303 | IMPORTANT QUESTIONS | @Express VTU 4 All 3
Methods of Process Termination:
a) Terminate All Deadlocked Processes
All processes involved in the deadlock are aborted
This completely eliminates the deadlock
Advantage:
Simple and effective
Disadvantage:
Causes loss of work done by processes
b) Terminate One Process at a Time
Processes are terminated one by one until the deadlock is resolved
After each termination, the system checks if the deadlock still exists
Criteria for selecting a process to terminate:
Priority of the process
Amount of computation done
Resources held by the process
Number of processes affected
Advantage:
Less work lost compared to terminating all processes
Disadvantage:
High overhead due to repeated checks
2. Deadlock Recovery by Resource Preemption
In this method, the operating system forcibly takes resources from one or
more processes and allocates them to other processes to break the deadlock.
Steps in Resource Preemption:
1. Select a Victim
Choose a process whose resources will be preempted
MODULE 3 | O.S. | BCS303 | IMPORTANT QUESTIONS | @Express VTU 4 All 4
Selection depends on cost, priority, and resource usage
2. Rollback
The victim process is rolled back to a safe state
Process can be restarted later
3. Avoid Starvation
Ensure the same process is not always selected as a victim
Aging techniques can be used
Advantage:
No need to terminate processes
Disadvantage:
Not all resources can be preempted
Rollback is complex
QUES 3 : What is a Semaphore? State the Dining
Philosopher Problem and Give a Solution Using
Semaphore.
ANS : Semaphore
A semaphore is a synchronization tool used in operating systems to control
access to shared resources by multiple processes or threads. It helps in
avoiding race conditions and ensures mutual exclusion.
A semaphore is an integer variable that can be accessed only through two
atomic operations:
wait() (also called P operation)
signal() (also called V operation)
MODULE 3 | O.S. | BCS303 | IMPORTANT QUESTIONS | @Express VTU 4 All 5
Semaphore Operations:
wait(S)
Decrements the value of semaphore S .
If S<0 , the process is blocked.
signal(S)
Increments the value of semaphore S .
If S≤0 , one waiting process is awakened.
Types of Semaphores:
1. Binary Semaphore – value is 0 or 1 (used for mutual exclusion)
2. Counting Semaphore – value can be any integer (used for resource
counting)
Dining Philosopher Problem
The Dining Philosopher Problem is a classic synchronization problem that
illustrates issues of deadlock and starvation.
Problem Description:
There are five philosophers sitting around a circular table.
Each philosopher alternates between thinking and eating.
There are five chopsticks, one between each pair of philosophers.
A philosopher needs two chopsticks (left and right) to eat.
A philosopher can pick up only one chopstick at a time.
If all philosophers pick up their left chopstick at the same time, deadlock
occurs, as each waits for the right chopstick.
Solution to Dining Philosopher Problem Using
Semaphore
To solve the problem, semaphores are used to control access to chopsticks
and prevent deadlock.
MODULE 3 | O.S. | BCS303 | IMPORTANT QUESTIONS | @Express VTU 4 All 6
Semaphore Initialization:
semaphore chopstick[5] = {1, 1, 1, 1, 1};
Each chopstick is represented by a binary semaphore.
Philosopher i Algorithm:
while (true) {
think();
wait(chopstick[i]); // pick left chopstick
wait(chopstick[(i+1)%5]); // pick right chopstick
eat();
signal(chopstick[i]); // release left chopstick
signal(chopstick[(i+1)%5]); // release right chopstick
}
Deadlock Prevention Technique:
To avoid deadlock, one common approach is:
Allow only four philosophers to sit at the table at the same time
OR
Make one philosopher pick the chopsticks in reverse order
This ensures that circular wait condition is avoided.
Advantages of Semaphore Solution
Ensures mutual exclusion
Prevents deadlock
Proper synchronization between processes
Disadvantages
Programming is complex
MODULE 3 | O.S. | BCS303 | IMPORTANT QUESTIONS | @Express VTU 4 All 7
Incorrect semaphore usage may lead to deadlock or starvation
Difficult to debug
QUES 4 :
ANS :
MODULE 3 | O.S. | BCS303 | IMPORTANT QUESTIONS | @Express VTU 4 All 8
MODULE 3 | O.S. | BCS303 | IMPORTANT QUESTIONS | @Express VTU 4 All 9
MODULE 3 | O.S. | BCS303 | IMPORTANT QUESTIONS | @Express VTU 4 All 10
MODULE 3 | O.S. | BCS303 | IMPORTANT QUESTIONS | @Express VTU 4 All 11