Practice
Solution
Step 1: Understand semaphore roles
'empty' counts available buffer slots; 'full' counts filled slots; mutex protects buffer access.Step 2: Producer must wait for empty slot
Producer waits (P operation) on 'empty' to ensure space is available before producing.Step 3: Acquire mutex before modifying buffer
Mutex wait ensures exclusive access to buffer.Step 4: Add item, then release mutex
After adding, signal (V operation) mutex to release critical section.Step 5: Signal 'full' to indicate new item
Signaling 'full' wakes consumers waiting for items.Step 6: Why other options fail
Wait on 'full' semaphore, wait on mutex, add item, signal mutex, signal 'empty' semaphore waits on 'full' which is incorrect; Wait on mutex, wait on 'empty' semaphore, add item, signal 'full' semaphore, signal mutex waits on mutex before 'empty' which can cause deadlock; Signal 'empty' semaphore, wait on mutex, add item, signal 'full' semaphore, wait on 'full' semaphore signals before waiting, breaking synchronization.Final Answer:
Option A -> Option AQuick Check:
Wait empty -> wait mutex -> produce -> signal mutex -> signal full [OK]
- Confusing 'full' and 'empty' semaphore roles
- Incorrect order of mutex and semaphore waits
- Signaling before waiting causing race
Solution
Step 1: Identify Banker's Algorithm assumptions
The algorithm requires prior knowledge of maximum resource needs for each process.Step 2: Analyze limitations
This requirement is often unrealistic in dynamic or unpredictable environments.Step 3: Evaluate other options
B is false; Banker's Algorithm handles multiple resource types.
C is false; it avoids deadlocks rather than causing them.
D is false; it does not preempt resources.Final Answer:
Option A -> Option AQuick Check:
Pre-declaration of max needs is the main practical limitation.
- Thinking it only supports one resource type
- Believing it causes deadlocks under load
- Confusing it with preemptive algorithms
Solution
Step 1: Understand SSTF starvation
SSTF always picks the nearest request, so requests far from the current head position may wait indefinitely.Step 2: SCAN and C-SCAN fairness
They move the head in a fixed direction, servicing all requests in order, ensuring no starvation.Step 3: Evaluate other options
Options B, C, and D contain incorrect claims: SSTF does not service requests in arrival order; it does not have higher overhead due to sorting; and it requires knowledge of all requests upfront similarly to SCAN and C-SCAN.Final Answer:
Option A -> Option AQuick Check:
SSTF picks the closest request, potentially ignoring far requests indefinitely; SCAN and C-SCAN guarantee servicing all requests by sweeping the disk head across all tracks. correctly explains starvation and fairness trade-offs.
- Confusing SSTF with FCFS regarding request order
- Assuming SSTF has higher computational overhead
- Believing SCAN/C-SCAN require less request knowledge
Solution
Step 1: Understand compaction process
Compaction moves allocated blocks to create contiguous free memory, reducing external fragmentation (A correct).Step 2: Analyze process halting
Compaction usually requires pausing processes to safely move memory (D incorrect).Step 3: Consider overhead and fragmentation
Compaction adds CPU overhead and can degrade performance temporarily (C correct); it does not affect internal fragmentation (B correct).Final Answer:
Option A -> Option AQuick Check:
Compaction generally requires halting processes [OK]
- Assuming compaction is transparent to running processes
- Confusing internal and external fragmentation effects
- Underestimating compaction overhead
Solution
Step 1: Understand starvation in non-preemptive SJF
Non-preemptive SJF can cause starvation if short jobs keep arriving, delaying longer jobs indefinitely.Step 2: Analyze other options
A: Correct, non-preemptive means no interruption once started.
B: Incorrect, non-preemptive SJF does not guarantee no starvation.
C: Correct, it can lead to longer average waiting time compared to preemptive SJF.
D: Correct, selection is based on shortest burst time when CPU is free.Final Answer:
Option D -> Option DQuick Check:
Non-preemptive SJF does not guarantee no starvation; starvation can occur.
- Assuming non-preemptive SJF prevents starvation
- Confusing preemptive and non-preemptive behavior
