OS Important M-3
OS Important M-3
rd
3 SEM Exam – Important Questions
MODULE – 3
1. What is critical section? What are the three requirements for critical section to satisfy
Ans:
Critical Section:
1. Exclusive Access: Critical section is a part of a program where shared resources are accessed or
modified.
2. Concurrency Concerns: It's crucial because multiple threads or processes may try to access shared
resources simultaneously.
3. Mutual Exclusion: Only one thread can execute the critical section at a time to prevent data
corruption or inconsistency.
4. Synchronization: Critical sections require synchronization mechanisms to ensure that only one
thread accesses the shared resource at any given time.
[Another Answer]
2. Illustrate Peterson’s solution for critical section problem
Ans:
3. What are monitors? Explain dining philosopher’s solution using monitor and using
semaphore.
Ans: Syntax and schematic view of Monitors:
[Extra Question]
Dining-Philosopher's problem using monitors:
4. What is Synchronization? Explain Synchronization Hardware
Ans:
Synchronization:
Synchronization Hardware:
3. Uniprocessor Environment:
In a uniprocessor environment, preventing interrupts while accessing shared variables
ensures that instructions are executed in order without interruption.
This prevents unexpected modifications to shared variables, as no other instructions are run
during critical sections.
4. Challenges in Multiprocessor Environment:
Disabling interrupts on a multiprocessor system is less feasible due to the overhead
involved.
Passing messages to all processors to disable interrupts delays entry into critical sections,
reducing system efficiency.
Multiprocessor systems require more sophisticated synchronization mechanisms to
coordinate access to shared resources efficiently.
5. What is deadlock? What are necessary conditions for deadlock
Ans:
Deadlock:
Deadlock is a state in a computer system where two or more processes are unable to proceed
because each is waiting for the other to release a resource, resulting in a standstill situation where
no progress can be made. Deadlock typically occurs in concurrent systems where processes
compete for shared resources and can arise due to improper resource allocation and
synchronization.
5. Banker's Algorithm Problems: [ Prepare for this question – Very Important]
Ans:
6. Various methods to recovery from deadlock
Ans:
Various methods of recovery from deadlock include:
1. Deadlock Prevention:
Proactive approach to prevent deadlock by ensuring that at least one of the necessary conditions
for deadlock cannot occur.
Examples include resource allocation strategies, such as bankers' algorithm, which ensures that
processes' resource requests are granted only if the resulting state is safe and deadlock-free.
2. Deadlock Avoidance:
Dynamic approach that involves carefully scheduling processes to avoid potential deadlock
situations.
Techniques include resource allocation algorithms that use information about the current state
and future resource requests to decide whether to grant or deny resource requests.
Examples include the use of resource allocation graphs and bankers' algorithm with additional
runtime checks.
3. Deadlock Detection and Recovery:
Reactive approach that detects deadlock after it has occurred and takes corrective action to
recover from it.
Techniques include periodically checking the system for deadlock using algorithms like the cycle
detection algorithm.
Upon detecting deadlock, recovery methods involve breaking the deadlock by preempting
resources from some processes, killing some processes, or rolling back the system to a previously
known safe state.
4. Resource Preemption:
Preempt resources from one or more processes to break the circular wait condition and resolve
the deadlock.
Preemption involves forcibly removing resources from processes to allocate them to other
processes to satisfy their resource needs.
Care must be taken to ensure that preemption does not lead to resource starvation or
inconsistency.
5. Process Termination:
Terminate one or more processes involved in the deadlock to release their held resources.
Selecting processes for termination can be based on factors such as process priority, resource
usage, and the impact of termination on system performance.
Termination should be done carefully to minimize disruption to the system and ensure that
terminated processes do not leave inconsistent or corrupt data.
6. Rollback and Restart:
Roll back the system to a previous checkpoint where deadlock did not exist and restart the
affected processes from that point.
Rollback involves reverting the system's state to a consistent state prior to the occurrence of
deadlock.
Restarting processes allows them to resume execution without being affected by the deadlock.
8. What is resource allocation Graph? Explain how it is very useful in describing deadly
embrace(deadlock) by considering an example