Sample questions
Question 1Easy
What information must each process declare in advance for the Banker's algorithm?
- Its total CPU burst time
- Its priority
- The order in which it will release resources
- Its maximum need for each resource type
Answer: D. Its maximum need for each resource type
Explanation
Banker's computes Need = Max - Allocation and uses it to test whether a safe sequence exists.
Step-by-step solution
- The Banker's algorithm needs to know how much of each resource a process might require.
- This is called the maximum need for each resource type.
- Processes must declare their maximum need in advance.
- The algorithm uses this to calculate Need = Max - Allocation.
- This helps determine if a safe sequence of resource allocation exists.
- Final answer: Its maximum need for each resource type.
Why the other options are wrong
- A. CPU burst time is not declared; the Banker's algorithm needs the maximum resource need of each resource type.
- B. Priority is not declared for the Banker's algorithm; it works from each process's maximum claim on resources.
- C. The order of releasing resources is not declared; the algorithm needs the maximum claim for each resource type.
Tip: Remember, the Banker's algorithm requires processes to declare their maximum resource needs in advance.
Question 2Easy
Starvation differs from deadlock because a starving process:
- Could proceed but keeps being passed over
- Holds every resource
- Has already terminated
- Is part of a circular wait
Answer: A. Could proceed but keeps being passed over
Explanation
- Starvation is indefinite postponement (often fixed by aging);
- deadlock is a set of processes waiting on each other.
Step-by-step solution
- Starvation means a process is denied resources indefinitely.
- It keeps getting postponed but could proceed if given resources.
- Deadlock involves circular wait and mutual exclusion.
- Starving process is not part of a deadlock cycle.
- Final answer: Could proceed but keeps being passed over.
Why the other options are wrong
- B. A starving process does not hold every resource; it keeps waiting while others proceed.
- C. A starving process has not terminated; it is still waiting to be scheduled.
- D. Starvation is not a circular wait; that is a deadlock condition.
Tip: Remember starvation is indefinite postponement, not mutual exclusion like deadlock.
Question 3Easy
Which situation is an example of deadlock?
- A low-priority process never gets the CPU because of higher-priority ones
- A process waits for I/O to complete
- Two processes each hold one lock and wait forever for the other's lock
- A process runs an infinite loop
Answer: C. Two processes each hold one lock and wait forever for the other's lock
Explanation
Each process waits for a resource held by the other: a two-process circular wait.
Step-by-step solution
- Process 1 holds lock A and waits for lock B.
- Process 2 holds lock B and waits for lock A.
- No process can proceed as each waits for the other's resource.
- This creates a circular wait condition between two processes.
- Final answer: Two processes each hold one lock and wait forever for the other's lock.
Why the other options are wrong
- A. A low-priority process waiting for the CPU is starvation, not deadlock, because no cycle of waiting processes exists.
- B. A process waiting for I/O is blocked but will continue once the I/O completes, so it is not deadlock.
- D. An infinite loop is a live process using the CPU, not a set of processes waiting on each other.
Tip: Look for circular wait conditions between resources.
Question 4Easy
In the Banker's algorithm state below (resources A, B, C), what is the Need of P2?
Process Allocation Max
P0 1 0 1 4 2 2
P1 2 1 1 3 2 2
P2 1 0 3 3 3 4
P3 0 2 0 2 4 3
P4 1 1 0 2 2 1
- (3, 3, 4)
- (2, 3, 1)
- (4, 3, 7)
- (1, 0, 3)
Answer: B. (2, 3, 1)
Explanation
Need = Max - Allocation
= (3, 3, 4) - (1, 0, 3)
= (2, 3, 1).
Step-by-step solution
- Need for P2 is Max minus Allocation.
- Max of P2 is (3, 3, 4).
- Allocation of P2 is (1, 0, 3).
- 3 - 1 = 2, 3 - 0 = 3, 4 - 3 = 1.
- Need of P2 is (2, 3, 1).
Why the other options are wrong
- A. (3, 3, 4) is the Max of P2, not its Need; Need is Max minus Allocation, which gives (2, 3, 1).
- C. (4, 3, 7) adds numbers instead of subtracting; Need is Max minus Allocation, giving (2, 3, 1).
- D. (1, 0, 3) is the Allocation of P2, not its Need, which is Max minus Allocation.
Question 5Medium
In a resource-allocation graph where every resource type has exactly one instance, a cycle means:
- There is no deadlock
- Deadlock exists
- Only starvation exists
- Deadlock may or may not exist
Answer: B. Deadlock exists
Explanation
With single-instance resources a cycle is both necessary and sufficient for deadlock.
Step-by-step solution
- Single-instance resources: a cycle is necessary and sufficient.
- So a cycle means deadlock.
Why the other options are wrong
- A. A cycle rules this out.
- C. Starvation is different.
- D. That holds for multi-instance resources.
Question 6Medium
Which deadlock condition is generally impossible to eliminate for resources such as printers?
- Mutual exclusion
- No preemption
- Circular wait
- Hold and wait
Answer: A. Mutual exclusion
Explanation
Some resources are inherently non-sharable; spooling helps for printers, but in general mutual exclusion cannot be denied.
Step-by-step solution
- Printers can only be used by one process at a time.
- This requires mutual exclusion to prevent conflicts.
- Spooling allows sharing but does not eliminate mutual exclusion.
- Mutual exclusion is necessary for printers and cannot be removed.
- Final answer: A (Mutual exclusion).
Why the other options are wrong
- B. Spooling handles printers by queueing jobs instead of holding the device, so no-preemption is not the condition that cannot be removed.
- C. Circular wait can be removed by ordering resource requests, so it is not the condition that cannot be removed.
- D. Hold and wait can be removed by requesting all resources at once, so it is not the condition that cannot be removed.
Question 7Medium
For resources that have only a single instance each, which structure is commonly used to detect deadlock?
- A wait-for graph, checked for cycles
- A page table
- A semaphore queue
- A Gantt chart
Answer: A. A wait-for graph, checked for cycles
Explanation
A wait-for graph is obtained by collapsing resource nodes of the resource allocation graph. A cycle in it means deadlock when every resource has one instance.
Step-by-step solution
- A wait-for graph shows which processes are waiting for resources.
- Checking for cycles in this graph detects deadlocks.
- Each resource has only one instance, so a cycle means deadlock.
- This is why a wait-for graph is used to detect deadlock.
- The correct answer is A (A wait-for graph, checked for cycles).
Why the other options are wrong
- B. A page table maps pages to frames; it has no waiting relations and cannot be used to detect deadlock.
- C. A semaphore queue lists waiting processes but does not show who waits for whom, so it cannot reveal cycles.
- D. A Gantt chart shows CPU timelines for scheduling; it is not used to detect deadlock.
Tip: Use wait-for graphs to check for cycles in single-instance resource systems.
Question 8Medium
Three processes each need at most 3 instances of a resource type. What is the minimum number of instances that guarantees deadlock can never occur?
- 4
- 7
- 9
- 6
Answer: B. 7
Explanation
Worst case: every process holds k - 1 = 2 instances and waits for one more, using 3 x 2 = 6.
One extra instance lets some process finish, so the minimum is 6 + 1 = 7.
Step-by-step solution
- Each process needs at most 3 instances.
- Worst case: each holds 2 and waits for 1 more, total 3 x 2 = 6.
- One extra instance ensures at least one process can finish.
- Total required is 6 + 1 = 7.
- Final answer: 7.
Why the other options are wrong
- A. With 4 instances, two processes can each hold 2 and wait for 1 more, so deadlock is still possible.
- C. 9 is more than needed; 7 instances already guarantee no deadlock, so 9 is not the minimum.
- D. With 6 instances all are held, each process waits for one more, so deadlock can still occur.
Tip: Add one more than the sum of (max needed - 1) for all processes.
Question 9Hard
Using the Banker's algorithm with resources A, B, C and Available = (3, 3, 2), which of the following is a safe sequence?
Process Allocation Max
P0 0 1 0 7 5 3
P1 2 0 0 3 2 2
P2 3 0 2 9 0 2
P3 2 1 1 2 2 2
P4 0 0 2 4 3 3
- P0, P1, P2, P3, P4
- P4, P3, P1, P2, P0
- P1, P3, P4, P0, P2
- P2, P1, P3, P4, P0
Answer: C. P1, P3, P4, P0, P2
Explanation
Need = Max - Allocation:
- P0 (7,4,3),
- P1 (1,2,2),
- P2 (6,0,0),
- P3 (0,1,1),
- P4 (4,3,1).
Work (3,3,2):
- P1 runs -> (5,3,2);
- P3 -> (7,4,3);
- P4 -> (7,4,5);
- P0 -> (7,5,5);
- P2 -> (10,5,7).
The other sequences fail at the first step: P0 needs 7 A, P2 needs 6 A, P4 needs 4 A while only 3 are available.
Step-by-step solution
- Need = Max − Allocation: P0 (7, 4, 3), P1 (1, 2, 2), P2 (6, 0, 0), P3 (0, 1, 1), P4 (4, 3, 1).
- Start with Available (3, 3, 2). P1 needs (1, 2, 2), which fits; after it finishes, Available is (5, 3, 2).
- P3 needs (0, 1, 1), which fits, giving (7, 4, 3). P4 needs (4, 3, 1), which fits, giving (7, 4, 5).
- P0 needs (7, 4, 3), which fits, giving (7, 5, 5). P2 then fits. All five finish, so the order P1, P3, P4, P0, P2 is the marked safe sequence.
Why the other options are wrong
- A. P0 is first and needs (7, 4, 3), which is more than Available (3, 3, 2), so this order is not safe.
- B. P4 is first and needs (4, 3, 1); its first value 4 is more than Available's 3, so it cannot run first.
- D. P2 is first and needs (6, 0, 0); its first value 6 is more than Available's 3, so it cannot run first.
Tip: Repeatedly pick any process whose Need fits Available, add its Allocation back, and check that all finish.
Question 10Hard
A system uses global resource ordering, but one thread acquires lock L5 and then tries to acquire L2. What is the risk?
- Only starvation is possible
- There is no risk, because the other threads still follow the ordering
- The program will not compile
- It violates the ordering, so circular wait (and deadlock) becomes possible
Answer: D. It violates the ordering, so circular wait (and deadlock) becomes possible
Explanation
Ordering prevents deadlock only if every thread follows it; one thread acquiring in decreasing order can complete a cycle.
Step-by-step solution
- Ordering works only if everyone acquires in increasing order.
- Taking L2 while holding L5 violates it.
- Another thread holding L2 and wanting L5 completes a cycle.
Why the other options are wrong
- A. Deadlock, not only starvation, is possible.
- B. One violator is enough.
- C. Lock order is a runtime matter.
Practise all 42 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →