GateMCQSCIENTIFIC PREP LAB
PlanSign Up
INTERMEDIATEFrequently Tested 4 min read 21 views

CPU Scheduling, Semaphores & Deadlock Banker’s Formula

TAT/WT numericals, counting semaphore wait/signal invariants, and minimum/maximum resource deadlock formulas.

Deadlock Resource Allocation Shortcut

Suppose nn processes each require at most kik_i instances of a single resource type RR:

  • Maximum resources WITH deadlock still possible: ∑i=1n(ki−1)\sum_{i=1}^{n} (k_i - 1)
  • Minimum resources GUARANTEEING NO deadlock: [∑i=1n(ki−1)]+1\left[\sum_{i=1}^{n} (k_i - 1)\right] + 1

Example: 4 processes each need max 33 tape drives. Max drives with deadlock =4(3−1)=8= 4(3 - 1) = 8. Minimum drives for zero deadlock =8+1=9= 8 + 1 = \mathbf{9}!

fork() System Call Process Creation

Calling fork() nn times sequentially creates 2n2^n total processes (11 original parent + 2n−12^n - 1 child processes).

Interactive CPU Scheduling Gantt Chart Simulator (SRTF, RR, SJF, FCFS)

Operating SystemsGantt + TAT/WT

CPU Scheduling Live Gantt Chart (SRTF / RR / SJF / FCFS)

Timeline t = 14 / 14
CPU Execution Gantt Chart:
P10–1
P21–4
P44–6
P16–10
P310–14
ProcessArrival (AT)Burst (BT)Completion (CT)TAT = CT − ATWT = TAT − BT
P10510105
P213430
P32414128
P442620
Average TAT = 6.75 • Average Waiting Time = 3.25

Interactive Banker’s Deadlock Safety Sequence Trace

Operating SystemsNeed ≤ Work Trace

Banker’s Deadlock Safety Sequence Step-by-Step

Current Work (Available) Vector: [A=3, B=3, C=2]
Safe Sequence: <...>
ProcAllocation (A,B,C)Max (A,B,C)Need = Max − AllocState
P0[0, 1, 0][7, 5, 3][7, 4, 3]Pending
P1[2, 0, 0][3, 2, 2][1, 2, 2]Pending
P2[3, 0, 2][9, 0, 2][6, 0, 0]Pending
P3[2, 1, 1][2, 2, 2][0, 1, 1]Pending
P4[0, 0, 2][4, 3, 3][4, 3, 1]Pending
Initial Available / Work vector = [3, 3, 2]. Scanning for any unfinished Pi with Need[i] ≤ Work.
Step 1 / 8
Key Formulas Summary
Counting Semaphore Final Value
Sfinal=Sinit−(#P/wait)+(#V/signal)S_{\text{final}} = S_{\text{init}} - (\#\text{P/wait}) + (\#\text{V/signal})
Note: If S_final < 0, then |S_final| processes are blocked in semaphore queue!
Deadlock-Free Minimum Resources
R≥∑i=1n(Maxi−1)+1R \ge \sum_{i=1}^{n} (\text{Max}_i - 1) + 1
Note: Guarantees at least 1 process gets all needed resources and finishes!
#Operating Systems#Scheduling#Semaphores#Deadlock

Practice Questions on This Chapter (6)

Q1GATE CS OS NATNATEASY
+2M • 0 Neg

A system has 55 processes, and each process requires a maximum of 44 instances of resource RR to complete execution. What is the minimum number of instances of RR that guarantees the system will NEVER enter deadlock?

Q2GATE CS OSMCQMEDIUM
+2M • -0.67

A C program executes fork(); fork(); fork(); sequentially without any conditional branching. Including the initial parent process, how many child processes are newly created?

⚡ Click an option above to verify instantly
Q3GATE CS OSMCQMEDIUM
+2M • -0.67

A counting semaphore SS is initialized to 1010. Subsequently, 66 wait(P) operations and 44 signal(V) operations are completed on SS. What is the current value of SS?

⚡ Click an option above to verify instantly
Q4UGC NET / GATE OSMCQMEDIUM
+2M • -0.67

A system has 33 processes, each requiring at most 44 identical units of resource RR. What is the minimum number of units of RR that guarantees the system is always deadlock-free?

⚡ Click an option above to verify instantly
Q5GATE CS 2024 Set-1NATMEDIUM
+2M • 0 Neg

Four processes P1,P2,P3,P4P_1, P_2, P_3, P_4 arrive at times 0,1,2,40, 1, 2, 4 with CPU burst times 5,3,3,15, 3, 3, 1 respectively. Under SRTF (Shortest Remaining Time First) preemptive scheduling, what is the average turnaround time?

Q6GATE CS 2016MCQMEDIUM
+2M • -0.67

Consider Peterson’s two-process software synchronization solution using shared flag[0..1] and turn. Which of the three Critical Section requirements (Mutual Exclusion, Progress, Bounded Waiting) does it satisfy on a sequentially consistent processor?

⚡ Click an option above to verify instantly
Previous TopicCompilers 2027 Rank-Decider: Basic-Block Leaders, SSA Phi-Functions, Dominators & Graph ColoringNext Topic Virtual Memory, Multi-Level Paging & TLB Effective Access Time