Priority Scheduling means allocating the CPU first to those processes has higher priority. Priority scheduling is one of the most common scheduling algorithms in batch systems. These post focus on priority scheduling algorithm.
Each process is assigned a priority. Process with the highest priority is to be executed first and so on.
A priority is a number in a range (for instance between 0 to 255) which is predefined by operating system.
A small number would mean high priority while a large number would mean low priority (It a as per LINUX system. It may vary to other system like large number would mean low priority while small number would mean high priority)
Scheduling policy pick the processes in the ready queue having the highest priority.
Processes with same priority are executed in First-Cum-First-Serve(FCFS) manner.
Priority can be decided based on memory requirements, time requirements or any other resource requirement.
Gantt represents the priority scheduling algorithm as:
As per LINUX Nomenclature:
0 12 35 42 47
Because of high priority of P3 it start executing, so waiting time is ‘0’ millisecond and others process is in waiting state. P2 waits for ’12’ millisecond, P1 waits for ’35’ millisecond, P4 waits for ’42’ millisecond.
P3 completion time is ’12’ millisecond, completion time is ’35’ millisecond, P1 completion time is ’42’ millisecond and P4 completion time is ’47’ millisecond.
The average waiting time as per the above represented Gantt chart (priority scheduling algorithm) is:
Average waiting time = 0 + 12 + 35 + 42 / 4
= 22.25 millisecond
Advantage of priority scheduling algorithm:
Mechanism to provide relative importance to processes
Disadvantage of priority scheduling algorithm:
Could lead starvation of low priority process