2078 3

CSC264 · 2078 · 10 marks

How unsafe state differs from deadlocked state? Consider the following initial state and identify whether requested is granted or denied for the given cases. What will happen if process D requests 1 resource? What will happen if process A requests 1 resource? | Process | Has | Max | |---------|-----

How unsafe state differs from deadlocked state? Consider the following initial state and identify whether requested is granted or denied for the given cases. What will happen if process D requests 1 resource? What will happen if process A requests 1 resource?

ProcessHasMax
A26
B15
C23
D38

$$\text{Free} = 2$$

[10]

Operating SystemsChapter 3: Process DeadlocksHandling DeadlocksNumerical: Safe state resource allocationVideo solution

Unsafe State vs Deadlocked State, and Banker's Algorithm Application

Given Data

ProcessHasMaxNeed = Max − Has
A264
B154
C231
D385

Free = 2

Total resources $= (2+1+2+3) + 2 = 10$ (single resource type).


Part 1: Unsafe State vs Deadlocked State

AspectUnsafe StateDeadlocked State
DefinitionNo guaranteed safe sequence exists to let all processes finishA set of processes is permanently blocked, each waiting on a resource held by another
ProgressProcesses may still run; deadlock has not necessarily happenedNo process can proceed at all
NatureA warning/potential problemAn actual, current problem
RelationshipSuperset: not every unsafe state leads to deadlockA deadlocked state is always unsafe (deadlock ⊆ unsafe)
HandlingBanker's Algorithm avoids it by denying dangerous requestsRequires detection + recovery

An unsafe state means the system might deadlock if unlucky future requests occur; a deadlocked state means it has already got stuck.


Part 2: Is the Initial State Safe?

Apply safety check with Free = 2. Look for a process with $\text{Need} \le \text{Free}$.

  • C: Need = 1 ≤ 2 → run. Free = $2 + 2 = 4$
  • A: Need = 4 ≤ 4 → run. Free = $4 + 2 = 6$
  • B: Need = 4 ≤ 6 → run. Free = $6 + 1 = 7$
  • D: Need = 5 ≤ 7 → run. Free = $7 + 3 = 10$

Safe sequence: C → A → B → D. The initial state is SAFE.


Part 3: Process D Requests 1 Resource

  1. Request = 1 ≤ Need(D) = 5 ✓
  2. Request = 1 ≤ Free = 2 ✓ (tentatively grant)

Tentative state: D: Has = 4, Need = 4. Free = $2 - 1 = 1$.

Safety check with Free = 1:

ProcessNeedNeed ≤ Free?
A4No
B4No
C1Yes
D4No
  • Run C: Free = $1 + 2 = 3$
  • Remaining A(4), B(4), D(4): none ≤ 3 → stuck

No safe sequence exists → UNSAFE state.

Conclusion: D's request is DENIED.


Part 4: Process A Requests 1 Resource

  1. Request = 1 ≤ Need(A) = 4 ✓
  2. Request = 1 ≤ Free = 2 ✓ (tentatively grant)

Tentative state: A: Has = 3, Need = 3. Free = $2 - 1 = 1$.

ProcessHasMaxNeed
A363
B154
C231
D385

Safety check with Free = 1:

  • C: Need = 1 ≤ 1 → run. Free = $1 + 2 = 3$
  • A: Need = 3 ≤ 3 → run. Free = $3 + 3 = 6$
  • B: Need = 4 ≤ 6 → run. Free = $6 + 1 = 7$
  • D: Need = 5 ≤ 7 → run. Free = $7 + 3 = 10$

Safe sequence: C → A → B → D. The resulting state is SAFE.

Conclusion: A's request is GRANTED.


Summary

RequestResult
Initial stateSAFE (C → A → B → D)
D requests 1DENIED (leads to unsafe state)
A requests 1GRANTED (state remains safe)

Parts 2 and 3 give an initially safe state with D's request denied, and Part 4 shows that A's request is GRANTED.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.