NivaarExam PrepOfficial exam papers ↗

25-Comp-A5 Operating Systems · Undated paper

Question 5 of 7: Deadlock Conditions, Read-Only Files, Resource-Bound Safety

Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)

Notes on this paper

Candidates were instructed to answer any five of the seven questions; all seven are answered below as a complete study resource.

Reference texts: Silberschatz, Galvin & Gagne, Operating System Concepts (10th ed.) — CPU scheduling (ch. 5), process synchronization/monitors (ch. 6–7), deadlocks (ch. 8), memory management/paging (ch. 9–10), mass-storage/file-system implementation and disk scheduling (ch. 11–12), protection (ch. 14); Tanenbaum, Modern Operating Systems (5th ed.), corroborating chapters on scheduling, synchronization, memory and file systems.

Question 5: Deadlock Conditions, Read-Only Files, Resource-Bound Safety (20 marks)

Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.

(a) Deadlock and its necessary conditions. A deadlock is a state in which a set of two or more processes are each waiting for a resource held by another process within that same set, forming a cycle of waits, so that none of them can ever proceed — no external intervention, no amount of scheduling, resolves it on its own. Four conditions must hold simultaneously for deadlock to be possible:

(b) Read-only files. No — a deadlock cannot occur solely from contention over read-only files. Deadlock's mutual-exclusion condition requires a resource to be held in a non-shareable way; a read-only file can be opened and read concurrently by any number of processes with no conflict, so no process ever needs to wait for exclusive access to it. With mutual exclusion never triggered for these resources, no circular wait over them can form, so deadlock cannot arise purely from read-only file access (though it remains possible if other, genuinely exclusive resources are involved).

(c) Deadlock-freedom bound for 7 processes, 15 identical resources

Given. $R=15$ identical resources; no deadlock-avoidance/prevention/detection is used (requests are granted greedily whenever a resource is free); processes $P_1..P_5$ have maximum simultaneous hold $=2$ each, $P_6,P_7$ have maximum simultaneous hold $=3$ each; each process requests/releases exactly one resource at a time.

Find. Whether deadlock can occur on this system.

Approach. Apply the standard sufficient condition for deadlock-freedom in a single-resource-type system: if the worst case in which every process holds one resource short of its maximum still leaves at least one resource spare, some process can always complete and release, guaranteeing progress.

  1. Compute the worst-case "everyone stuck one short of max" total. $$\sum_i (\max_i - 1) = 5\times(2-1) + 2\times(3-1) = 5\times1 + 2\times2 = 5+4=9$$
  2. Compare against total resources. $R=15 > 9$, so even in the absolute worst case where every process is holding $\max_i-1$ resources and blocked waiting for one more, $15-9=6$ resources remain unallocated — meaning at least one waiting process's next request must be satisfiable immediately (a resource is available), letting that process reach its maximum, complete its work, and release everything it holds, which then unblocks the others in turn. $$\boxed{\textstyle\sum_i(\max_i-1)=9 \lt R=15 \implies \text{deadlock is IMPOSSIBLE on this system}}$$
Final Results – Question 5(c)
QuantityValue
$\sum(\max_i-1)$9
Total resources $R$15
Deadlock possible?No — 15 > 9 guarantees progress