Priority Scheduling Examples

Priority Scheduling is a CPU scheduling algorithm in which each process is assigned a priority, and the CPU always executes the process with the highest priority first. Priority is a numeric value, depending on the OS or scheduling policy; sometimes a smaller number indicates a higher priority, and sometimes a higher number indicates a higher priority

Priority scheduling can be Preemptive or non-preemptive.

  • In non-preemptive scheduling, once a process gets the CPU, it continues until it completes. A new incoming process never interrupts the currently executing process.
  • In preemptive scheduling, once a process gets the CPU, it may be interrupted by the arrival of a higher-priority process. The higher-priority process immediately gets the CPU.

We will see various examples of priority preemptive and non-preemptive scheduling

Non-Preemptive Priority Scheduling Example 1

Consider the following relation which includes the Processes ID, Arrival time, and burst time.

Priority Scheduling Example - 1- Non-Preemptive

Gannt. Chart of the preemptive priority scheduling example 1 is given below, which shows the process when

  • it gets the CPU for the first time
  • and completes its execution

Priority Scheduling Example - 1- Non-Preemptive - Gantt Chart

Let’s calculate the When a process gets the CPU first time, Completion Time (CT), Waiting Time (WT), Turnaround Time (TAT), Average Waiting Time (AWT), Average Turnaround Time (ATAT), and Response Time (RT) of example 1

Process ID is set according to Priority to solve Example 1

Priority Scheduling Example - 1- Non-Preemptive - Solution

Non-Preemptive Priority Scheduling Example 2

Consider the following relation, which includes the Process ID, Arrival time, and burst time.

Priority Scheduling Example - 2- Non-Preemptive

Gannt. Chart of the preemptive priority scheduling example 1 is given below, which shows the process when

  • it gets the CPU for the first time
  • and completes its execution

Priority Scheduling Example - 2- Non-Preemptive - Gantt Chart

Let’s calculate when a process gets the CPU for the first time, Completion Time (CT), Waiting Time (WT), Turnaround Time (TAT), Average Waiting Time (AWT), Average Turnaround Time (ATAT), and Response Time (RT) of example 2

Process ID is set according to Priority to solve Example 2

Priority Scheduling Example - 2- Non-Preemptive - Solution

 

Non-Preemptive Priority Scheduling Example 3

Consider the following relation, which includes the Process ID, Arrival time, and burst time.

Priority Scheduling Example - 3- Non-Preemptive

Gannt. Chart of the preemptive priority scheduling example 1 is given below, which shows the process when

  • it gets the CPU for the first time
  • and completes its execution

Priority Scheduling Example - 3 - Non-Preemptive - Gantt Chart

Let’s calculate when a process gets the CPU for the first time, Completion Time (CT), Waiting Time (WT), Turnaround Time (TAT), Average Waiting Time (AWT), Average Turnaround Time (ATAT), and Response Time (RT) of Example 3

Process ID is set according to Priority to solve Example 3

Priority Scheduling Example - 3 - Non-Preemptive - Solution

Non-Preemptive Priority Scheduling Example 4

Consider the following relation, which includes the Process ID, Arrival time, and burst time.

Priority Scheduling Example - 5- Non-Preemptive

Gannt. Chart of the preemptive priority scheduling example 4 is given below, which shows the process when

  • it gets the CPU for the first time
  • and completes its execution

Priority Scheduling Example - 5- Non-Preemptive - Gantt Chart

Note: Time 22 to 23 and 25 to 30 is CPU idle time in Gantt. Chart

Let’s calculate when a process gets the CPU for the first time, Completion Time (CT), Waiting Time (WT), Turnaround Time (TAT), Average Waiting Time (AWT), Average Turnaround Time (ATAT), and Response Time (RT) of Example 4

Priority Scheduling Example - 5- Non-Preemptive - Solution

Note: we can calculate CPU utilization and Throughput using the following formulas

  • CPU Utilization = (Total Time – Idle Time) / Total = 36 – 6/36 = 30/36
  •  Throughput = Number of Processes Completed / Total Time  = 3/36

Note: Total time is the time from when the first process arrives to when the last process terminates in the Gantt chart.

Preemptive Priority Scheduling Example 1

Consider the following relation, which includes the Process ID, Arrival time, and burst time.

Priority Scheduling Example 1 - Preemptive

Gannt. Chart of the preemptive priority scheduling example 1 is given below, which shows the process when

  • it gets the CPU for the first time
  • and completes its execution

Priority Scheduling Example 1 - Gantt Chart

Let’s calculate when a process gets the CPU for the first time, Completion Time (CT), Waiting Time (WT), Turnaround Time (TAT), Average Waiting Time (AWT), Average Turnaround Time (ATAT), and Response Time (RT) of preemptive priority scheduling example 1

Preemptive Priority Scheduling Example 1 - Solution

Preemptive Priority Scheduling Example 2

Consider the following relation, which includes the Process ID, Arrival time, and burst time.

Priority Scheduling Example 2 - Preemptive

Gannt. Chart of the preemptive priority scheduling example 2 is given below, which shows the process when

  • it gets the CPU for the first time
  • and completes its execution

Priority Scheduling Example 2 - Gantt Chart

Let’s calculate when a process gets the CPU for the first time, Completion Time (CT), Waiting Time (WT), Turnaround Time (TAT), Average Waiting Time (AWT), Average Turnaround Time (ATAT), and Response Time (RT) of preemptive priority scheduling example 2

Preemptive Priority Scheduling Example 2 - Solution

Preemptive Priority Scheduling Example 3

Consider the following relation, which includes the Process ID, Arrival time, and burst time.

Priority Scheduling Example 3 - Preemptive

Gannt. Chart of the preemptive priority scheduling example 3 is given below, which shows the process when

  • it gets the CPU for the first time
  • and completes its execution

Priority Scheduling Example 3 - Gantt Chart

Let’s calculate when a process gets the CPU for the first time, Completion Time (CT), Waiting Time (WT), Turnaround Time (TAT), Average Waiting Time (AWT), Average Turnaround Time (ATAT), and Response Time (RT) of preemptive priority scheduling example 3

Preemptive Priority Scheduling Example 3 - Solution

Preemptive Priority Scheduling Example 4

Consider the following relation, which includes the Process ID, Arrival time, and burst time.

Priority Scheduling Example 4 - Preemptive

Let’s calculate when a process gets the CPU for the first time, Completion Time (CT), Waiting Time (WT), Turnaround Time (TAT), Average Waiting Time (AWT), Average Turnaround Time (ATAT), and Response Time (RT) of preemptive priority scheduling example 4

Priority Scheduling Example 4 - Gantt Chart

Let’s calculate when a process gets the CPU for the first time, Completion Time (CT), Waiting Time (WT), Turnaround Time (TAT), Average Waiting Time (AWT), Average Turnaround Time (ATAT), and Response Time (RT) of preemptive priority scheduling example 4

Preemptive Priority Scheduling Example 4 - Solution