PS(Priority Scheduling) non-premptive question

Here are 26 questions on PS(Priority Scheduling) process scheduling algorithms (premptive And non-premptive). Each question is presented in a table format, followed by the solution with Gantt charts, average turnaround time (TAT), and average waiting time (WT).


Jump To Question

What Is Priority Scheduling Algorithm in Operating System?

The Priority Scheduling algorithm in operating systems allocates CPU to the processes based on priority. Each process is assigned a priority, and the CPU is assigned to the process with the highest priority. Lower-priority processes wait until higher-priority ones finish, ensuring that essential processes get CPU time as needed.

Method for Priority Scheduling Algorithm

  • Step 1: Assign a priority number to each process.
  • Step 2: Compare the priority of each process in the ready queue.
  • Step 3: Select the process with the highest priority and allocate the CPU to it.
  • Step 4: If two processes have the same priority, use an alternate scheduling algorithm (e.g., FCFS ) to decide the order.
  • Step 5: Once the process is completed, move to the next highest-priority process.
  • Repeat until all processes in the queue have executed.

Advantages and Disadvantages of Priority Scheduling Algorithm

Advantages Disadvantages
Ensures important processes execute first. Can lead to starvation for lower-priority processes.
Can be customized to specific needs. Complexity increases with more processes.
Efficient for real-time systems. May require additional calculations for priority.
Flexible for process priority adjustments. Risk of priority inversion issues.
Less overhead for high-priority tasks. CPU utilization can be low for non-essential tasks.
Reduces wait time for critical processes. Can lead to unpredictable CPU allocation.

Why Priority Scheduling is Better Than Other Scheduling Algorithms?

Priority scheduling is often favored in systems that require high responsiveness for critical tasks, such as real-time systems, because it ensures essential processes are given priority access to the CPU. Compared to algorithms like FCFS or Round Robin, priority scheduling minimizes the wait time for critical applications and can be optimized further with priority adjustments, making it adaptable and highly effective for time-sensitive applications.

Question 1 : find the average Turn Around Time and Waiting Time of following processes using Non-Preemptive PS(Priority Scheduling) process scheduling algorithm?

Process Arrival Time Burst Time Priority
P1 0 8 2
P2 1 4 1
P3 2 9 3
P4 3 5 4

Solution :

lower number represents higher priority (here i take 1 as a highest priority)

Formula:

  • Turnaround Time = Completion Time - Arrival Time
  • Waiting Time = Turnaround Time - Burst Time
  • Average Turnaround Time = Sum of Turnaround Times / Number of Processes
  • Average Waiting Time = Sum of Waiting Times / Number of Processes

Gantt Chart

Priority Scheduling | Question 1 Solution | Gantt Chart
Process Completion Time Turnaround Time Waiting Time
P1 8 8 0
P2 12 11 7
P3 21 19 10
P4 26 23 18

Average Turnaround Time: (8+11+19+23)/4 = 15.25

Average Waiting Time: (0+7+10+18)/4 = 8.75

Question 2 : Preemptive Priority Scheduling

find the average Turn Around Time and Waiting Time of following processes using Preemptive PS(Priority Scheduling) process scheduling algorithm?

Process Arrival Time Burst Time Priority
P1 0 6 1
P2 2 2 3
P3 4 8 2
P4 6 4 4

Solution :

lower number represents higher priority (here i take 1 as a highest priority)

Formula:

  • Turnaround Time = Completion Time - Arrival Time
  • Waiting Time = Turnaround Time - Burst Time
  • Average Turnaround Time = Sum of Turnaround Times / Number of Processes
  • Average Waiting Time = Sum of Waiting Times / Number of Processes

Gantt Chart

Priority Scheduling | Question 2 Solution | Gantt Chart
Process Completion Time Turnaround Time Waiting Time
P1 6 6 0
P2 16 14 12
P3 14 10 2
P4 20 14 10

Average Turnaround Time: (6+14+10+14)/4 = 11

Average Waiting Time: (0+12+2+10)/4 = 6

Question 3 :Non-Preemptive Priority Scheduling

find the average Turn Around Time and Waiting Time of following processes using Non-Preemptive PS(Priority Scheduling) process scheduling algorithm?

Process Arrival Time Burst Time Priority
P1 0 5 3
P2 1 3 1
P3 2 4 2
P4 3 6 4

Solution :

lower number represents higher priority (here i take 1 as a highest priority)

Formula:

  • Turnaround Time = Completion Time - Arrival Time
  • Waiting Time = Turnaround Time - Burst Time
  • Average Turnaround Time = Sum of Turnaround Times / Number of Processes
  • Average Waiting Time = Sum of Waiting Times / Number of Processes

Gantt Chart

Priority Scheduling | Question 3 Solution | Gantt Chart
Process Completion Time Turnaround Time Waiting Time
P1 5 5 0
P2 8 7 4
P3 12 10 6
P4 18 15 9

Average Turnaround Time: (5+7+10+15)/4 = 9.25

Average Waiting Time: (0+4+6+9)/4 = 4.75

Question 4 : Preemptive Priority Scheduling

find the average Turn Around Time and Waiting Time of following processes using Preemptive PS(Priority Scheduling) process scheduling algorithm?

Process Arrival Time Burst Time Priority
P1 0 7 2
P2 1 4 1
P3 2 6 3
P4 3 3 4

Solution :

lower number represents higher priority (here i take 1 as a highest priority)

Formula:

  • Turnaround Time = Completion Time - Arrival Time
  • Waiting Time = Turnaround Time - Burst Time
  • Average Turnaround Time = Sum of Turnaround Times / Number of Processes
  • Average Waiting Time = Sum of Waiting Times / Number of Processes

Gantt Chart

Priority Scheduling | Question 4 Solution | Gantt Chart
Process Completion Time Turnaround Time Waiting Time
P1 11 11 4
P2 5 4 0
P3 17 15 9
P4 20 17 14

Average Turnaround Time: (11+4+15+17)/4 = 11.75

Average Waiting Time: (4+0+9+14)/4 = 6.75

Question 5 : Non-Preemptive Priority Scheduling

find the average Turn Around Time and Waiting Time of following processes using Non-Preemptive PS(Priority Scheduling) process scheduling algorithm? Consider the following processes with their Arrival Time, Burst Time, and Priority:

Process Arrival Time Burst Time Priority
P1 0 3 2
P2 2 5 1
P3 4 8 3
P4 6 6 4

Solution :

Formula:

  • Turnaround Time = Completion Time - Arrival Time
  • Waiting Time = Turnaround Time - Burst Time
  • Average Turnaround Time = Sum of Turnaround Times / Number of Processes
  • Average Waiting Time = Sum of Waiting Times / Number of Processes

Gantt Chart

Priority Scheduling | Question 5 Solution | Gantt Chart
Process Completion Time Turnaround Time Waiting Time
P1 3 3 0
P2 8 6 1
P3 16 12 4
P4 22 16 10

Average Turnaround Time: (3+6+12+16)/4 = 9.25

Average Waiting Time: (0+1+4+10)/4 = 3.75

Question 6: Non-Preemptive Priority Scheduling

find the average Turn Around Time and Waiting Time of following processes using Non-Preemptive PS(Priority Scheduling) process scheduling algorithm? Consider the following processes with their Arrival Time, Burst Time, and Priority:

Process Arrival Time Burst Time Priority
P1 0 5 2
P2 2 3 1
P3 4 1 4
P4 6 2 3

Solution :

lower number represents higher priority (here i take 1 as a highest priority)

Formula:

  • Turnaround Time = Completion Time - Arrival Time
  • Waiting Time = Turnaround Time - Burst Time
  • Average Turnaround Time = Sum of Turnaround Times / Number of Processes
  • Average Waiting Time = Sum of Waiting Times / Number of Processes

Gantt Chart

Priority Scheduling | Question 6 Solution | Gantt Chart
Process Arrival Time Burst Time Priority Completion Time Turnaround Time (TAT) Waiting Time (WT)
P1 0 5 2 5 5 - 0 = 5 5 - 5 = 0
P2 2 3 1 8 8 - 2 = 6 6 - 3 = 3
P3 4 1 4 11 11 - 4 = 7 7 - 1 = 6
P4 6 2 3 10 10 - 6 = 4 4 - 2 = 2
Average Turnaround Time:

(5 + 6 + 7 + 4) / 4 = 5.5 units

Average Waiting Time:

(0 + 3 + 6 + 2) / 4 = 2.75 units

Question 7 : Preemptive Priority Scheduling

find the average Turn Around Time and Waiting Time of following processes using Non-Preemptive PS(Priority Scheduling) process scheduling algorithm? Consider the following processes with their Arrival Time, Burst Time, and Priority:

Process Arrival Time Burst Time Priority
P1 0 7 1
P2 2 4 2
P3 4 1 3
P4 5 3 1
P5 6 2 4

Solution :

lower number represents higher priority (here i take 1 as a highest priority)

Formula:

  • Turnaround Time = Completion Time - Arrival Time
  • Waiting Time = Turnaround Time - Burst Time
  • Average Turnaround Time = Sum of Turnaround Times / Number of Processes
  • Average Waiting Time = Sum of Waiting Times / Number of Processes

Gantt Chart

Priority Scheduling | Question 7 Solution | Gantt Chart
Process Arrival Time Burst Time Priority Completion Time Turnaround Time (TAT) Waiting Time (WT)
P1 0 7 1 7 7 - 0 = 7 7 - 7 = 0
P2 2 4 2 14 14 - 2 = 12 12 - 4 = 8
P3 4 1 3 15 15 - 4 = 11 11 - 1 = 10
P4 5 3 1 10 10 - 5 = 5 5 - 3 = 2
P5 6 2 4 17 17 - 6 = 11 11 - 2 = 09
Average Turnaround Time:

(7+12+11+5+11) / 5 = 9.2 units

Average Waiting Time:

(0+8+10+2+9) / 5 = 5.8 units

Question 8: Non-Preemptive Priority Scheduling

find the average Turn Around Time and Waiting Time of following processes using Non-Preemptive PS(Priority Scheduling) process scheduling algorithm? Consider the following processes with their Arrival Time, Burst Time, and Priority:

Process Arrival Time Burst Time Priority
P1 1 3 3
P2 2 6 2
P3 3 4 1
P4 5 5 4

Solution :

lower number represents higher priority (here i take 1 as a highest priority)

Formula:

  • Turnaround Time = Completion Time - Arrival Time
  • Waiting Time = Turnaround Time - Burst Time
  • Average Turnaround Time = Sum of Turnaround Times / Number of Processes
  • Average Waiting Time = Sum of Waiting Times / Number of Processes

Gantt Chart

Priority Scheduling | Question 8 Solution | Gantt Chart
Process Arrival Time Burst Time Priority Completion Time Turnaround Time (TAT) Waiting Time (WT)
P1 1 3 3 4 4 - 1 = 3 3 - 3 = 0
P2 2 6 2 14 14 - 2 = 12 12 - 6 = 6
P3 3 4 1 8 8 - 3 = 5 5 - 4 = 1
P4 5 5 4 19 19 - 5 = 14 14 - 5 = 9
Average Turnaround Time:

(3 + 12 + 5 + 14) / 4 = 8.5 units

Average Waiting Time:

(0 + 6 + 1 + 9) / 4 = 4 units

Question 9: Preemptive Priority Scheduling

find the average Turn Around Time and Waiting Time of following processes using Preemptive PS(Priority Scheduling) process scheduling algorithm? Consider the following processes with their Arrival Time, Burst Time, and Priority:

Process Arrival Time Burst Time Priority
P1 0 8 1
P2 1 4 3
P3 2 9 2
P4 3 5 4
P5 4 6 5

Solution :

lower number represents higher priority (here i take 1 as a highest priority)

Formula:

  • Turnaround Time = Completion Time - Arrival Time
  • Waiting Time = Turnaround Time - Burst Time
  • Average Turnaround Time = Sum of Turnaround Times / Number of Processes
  • Average Waiting Time = Sum of Waiting Times / Number of Processes

Gantt Chart

Priority Scheduling | Question 9 Solution | Gantt Chart
Process Arrival Time Burst Time Priority Completion Time Turnaround Time (TAT) Waiting Time (WT)
P1 0 8 1 8 8 - 0 = 8 8 - 8 = 0
P2 1 4 3 21 21 - 1 = 20 20 - 4 = 16
P3 2 9 2 17 17 - 2 = 15 15 - 9 = 6
P4 3 5 4 26 26 - 3 = 23 23 - 5 = 18
P5 4 6 5 32 32 - 4 = 28 28 - 6 = 22
Average Turnaround Time:

(20 + 8 + 15 + 23 + 28) / 5 = 18.8 units

Average Waiting Time:

(0 + 16 + 6 + 18 + 22) / 5 = 12.4 units

Question 10: Non-Preemptive Priority Scheduling

find the average Turn Around Time and Waiting Time of following processes using Non-Preemptive PS(Priority Scheduling) process scheduling algorithm? Consider the following processes with their Arrival Time, Burst Time, and Priority:

Process Arrival Time Burst Time Priority
P1 1 5 2
P2 2 3 1
P3 3 6 4
P4 4 4 3
P5 5 2 5

Solution :

lower number represents higher priority (here i take 1 as a highest priority)

Formula:

  • Turnaround Time = Completion Time - Arrival Time
  • Waiting Time = Turnaround Time - Burst Time
  • Average Turnaround Time = Sum of Turnaround Times / Number of Processes
  • Average Waiting Time = Sum of Waiting Times / Number of Processes

Gantt Chart

Priority Scheduling | Question 10 Solution | Gantt Chart
Process Arrival Time Burst Time Priority Completion Time Turnaround Time (TAT) Waiting Time (WT)
P1 1 5 2 6 6 - 1 = 5 5 - 5 = 0
P2 2 3 1 9 9 - 2 = 7 7 - 3 = 4
P3 3 6 4 19 19 - 3 = 16 16 - 6 = 10
P4 4 4 3 13 13 - 4 = 9 19 - 4 = 5
P5 5 2 5 21 21 - 5 = 16 16 - 2 = 14
Average Turnaround Time:

(5 + 7 + 16 + 9 + 16) / 5 = 10.6 units

Average Waiting Time:

(0 + 4 + 10 + 5+ 14) / 5 = 6.6 units