0
0
Operating Systemsknowledge~10 mins

Priority scheduling in Operating Systems - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Priority scheduling
Start: Processes arrive
Assign priority to each process
Check ready queue
Select process with highest priority
Execute selected process
Process completes or is preempted
Update ready queue
Back to Check ready queue
Priority scheduling picks the process with the highest priority from the ready queue to run next, repeating this until all processes finish.
Execution Sample
Operating Systems
Processes = [P1(priority=3), P2(priority=1), P3(priority=4)]
ReadyQueue = [P1, P2, P3]
while ReadyQueue not empty:
  Pick process with highest priority
  Run process
  Remove process from ReadyQueue
This example shows selecting and running processes based on their priority until none remain.
Analysis Table
StepReady QueueSelected ProcessReasonActionRemaining Queue
1[P1(3), P2(1), P3(4)]P2(1)P2 has highest priority (lowest number)Run P2[P1(3), P3(4)]
2[P1(3), P3(4)]P1(3)P1 has next highest priorityRun P1[P3(4)]
3[P3(4)]P3(4)Only process leftRun P3[]
4[]-No processes leftStop scheduling[]
💡 Ready queue is empty, all processes have been executed.
State Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
ReadyQueue[P1(3), P2(1), P3(4)][P1(3), P3(4)][P3(4)][][]
SelectedProcess-P2(1)P1(3)P3(4)-
Key Insights - 3 Insights
Why is P2 selected first even though it appears second in the queue?
Because priority scheduling selects the process with the highest priority (lowest priority number), not the order in the queue. See execution_table step 1.
What happens when the ready queue becomes empty?
Scheduling stops because there are no more processes to run, as shown in execution_table step 4.
Does priority scheduling always run processes in arrival order?
No, it runs processes based on priority, not arrival order. The process with the highest priority runs first regardless of arrival time.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table. Which process is selected at step 2?
AP3
BP2
CP1
DNo process
💡 Hint
Check the 'Selected Process' column at step 2 in the execution_table.
At which step does the ready queue become empty?
AStep 1
BStep 4
CStep 3
DNever
💡 Hint
Look at the 'Ready Queue' column and find when it shows [].
If P3 had priority 0 (highest), which process would run first?
AP3
BP2
CP1
DNone
💡 Hint
Priority scheduling picks the process with the lowest priority number first, see variable_tracker for priority values.
Concept Snapshot
Priority Scheduling:
- Assign priority number to each process (lower number = higher priority).
- Always pick the process with highest priority to run next.
- Continue until all processes finish.
- Does not necessarily follow arrival order.
- Can be preemptive or non-preemptive.
Full Transcript
Priority scheduling is a method where the operating system selects the process with the highest priority to run next. Each process is assigned a priority number; the lower the number, the higher the priority. The scheduler looks at the ready queue, picks the process with the highest priority, runs it, then removes it from the queue. This repeats until no processes remain. The execution table shows step-by-step which process runs and how the queue changes. Key points include that priority, not arrival order, determines execution, and scheduling stops when the queue is empty.