Priority Scheduling Algorithm

3
0

Introduction

Priority scheduling is a CPU scheduling approach where the scheduler gives preference to the highest-priority ready process. A process with higher priority can get the CPU before other waiting processes.

This is useful because all processes are not equally important. Some system, urgent, interactive, or real-time tasks may need CPU attention before normal batch work.

Why Priority Scheduling Is Needed

Priority scheduling is used when the operating system needs to treat some work as more important than other work. Instead of selecting only by arrival time or burst time, the scheduler uses a priority value.

Common examples include:

  • System task before user task: Kernel or system work may need faster service.

  • Real-time task before regular task: Deadline-based work may need higher priority.

Core Rule of Priority Scheduling

The scheduler chooses the highest-priority process from the ready queue. In this editorial, a smaller priority number means higher priority.

If two processes have the same priority, arrival time can be used as a tie-breaker. The worked example uses non-preemptive priority scheduling, so a selected process runs until it completes.

Priority Scheduling Example

Consider five processes:

Process

Arrival Time

Burst Time

Priority

P1

0

8

3

P2

1

4

1

P3

2

9

4

P4

3

5

2

P5

7

2

1

Smaller priority number means higher priority. The scheduling is non-preemptive.

Priority Scheduling Example

Priority Scheduling Example

The compact scheduling flow is:

  • At time 0, only P1 has arrived, so P1 runs from 0 to 8.

  • At time 8, P2, P3, P4, and P5 are available.

  • P2 and P5 both have priority 1, so earlier arrival selects P2.

  • After P2, P5 runs, then P4, and finally P3.

Process

CPU Time Interval

P1

0 to 8

P2

8 to 12

P5

12 to 14

P4

14 to 19

P3

19 to 28

Metric Calculation

The main formulas are:

  • CT: finish time of the process

  • TAT: CT - AT

  • WT: TAT - BT

  • RT: first start time - AT

Process

CT

TAT

WT

RT

P1

8

8

0

0

P2

12

11

7

7

P3

28

26

17

17

P4

19

16

11

11

P5

14

7

5

5

Average TAT = 13.6, average WT = 8.0, and average RT = 8.0.

Aging and Starvation

The main risk in priority scheduling is starvation. A low-priority process may wait for a very long time if higher-priority processes keep arriving.

Aging helps reduce this problem. In aging, the priority of a waiting process is gradually improved as its waiting time increases. This ensures that long-waiting processes eventually get a fair chance to run.

Strengths and Weaknesses of Priority Scheduling

Strengths

Weaknesses

Handles important work first

Low-priority processes may starve

Useful for system and real-time tasks

Priority assignment can be difficult

Can use aging to reduce starvation

Priority inversion can occur with shared resources

Summary

Priority scheduling selects the highest-priority ready process. In the example used here, smaller priority numbers mean higher priority, and ties are handled using earlier arrival time.

It is useful when some work is more important than other work, especially in system, urgent, interactive, or real-time cases. Its main risks are starvation, unfairness, and priority inversion, so aging and careful priority design are important.

CS Core

Read Similar Blogs

Comments0