Premptive Priority Scheduling Question



Here are 31 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 Preemptive Priority Scheduling in Operating Systems?

Preemptive Priority Scheduling is a CPU scheduling algorithm where each process is assigned a priority level. The CPU is allocated to the process with the highest priority, and if a new process with a higher priority arrives, the currently running process is preempted and the CPU is allocated to the new process.

Method to Solve Preemptive Priority Scheduling Problems

  • Assign a priority level to each process.
  • Sort the processes in a priority queue based on their priority levels, with the highest priority first.
  • When the CPU becomes available, allocate it to the process with the highest priority.
  • If a new process arrives with a higher priority than the current running process, preempt the running process and allocate the CPU to the new process.
  • Continue this process until all tasks are completed, re-evaluating the priority queue as new processes arrive or are completed.
  • Calculate metrics like waiting time, turnaround time, and response time for performance analysis.

Advantages and Disadvantages of Preemptive Priority Scheduling

Advantages Disadvantages
Ensures high-priority processes receive CPU time first Can cause starvation of lower-priority processes
Responsive to critical real-time processes Requires complex priority assignment and management
Allows higher throughput for important tasks Overhead due to frequent context switching
Better control over process prioritization Priority inversion can occur without special handling
Improves resource utilization for important tasks Can increase response time for lower-priority processes
Effective in real-time systems requiring strict prioritization Requires a well-defined priority structure, which can be challenging

Why Preemptive Priority Scheduling is Better Than Other Algorithms?

Preemptive Priority Scheduling is often better than other scheduling algorithms, like First-Come, First-Served (FCFS) or Round Robin, because it can prioritize critical or time-sensitive processes. This feature is beneficial in real-time systems where certain tasks must complete within a specific time frame, making it a flexible and efficient choice for priority-driven environments.

Why Preemptive Priority Scheduling is Not the Best Algorithm for CPU Scheduling

Despite its advantages, Preemptive Priority Scheduling has limitations, such as the risk of starvation for low-priority processes and high context-switching overhead. Additionally, setting and managing priorities can be complex, especially for dynamic workloads. As a result, it may not be the best choice for general-purpose operating systems that require fair and balanced CPU allocation for all processes.

Question 11: 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 5 3
P2 1 3 1
P3 2 4 4
P4 3 2 2
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

| P1 (0-1) | P2 (1-4) | P4 (4-6) | P1 (6-8) | P3 (8-12) | P5 (12-18) |

Process Completion Time Turnaround Time (TAT) Waiting Time (WT)
P1 8 8 - 0 = 8 8 - 5 = 3
P2 4 4 - 1 = 3 3 - 3 = 0
P3 12 12 - 2 = 10 10 - 4 = 6
P4 6 6 - 3 = 3 3 - 2 = 1
P5 18 18 - 4 = 14 14 - 6 = 8
Average Turnaround Time:

(8 + 3 + 10 + 3 + 14) / 5 = 7.6 units

Average Waiting Time:

(3 + 0 + 6 + 1 + 8) / 5 = 3.6 units

Gantt Chart

| P1 (0-1) | P2 (1-4) | P4 (4-6) | P1 (6-8) | P3 (8-12) | P5 (12-18) |

Question 12: 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 1 3 2
P2 2 4 1
P3 3 6 4
P4 4 2 3
P5 5 5 5
P6 6 1 6

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

| P1 (1-4) | P2 (4-8) | P3 (8-14) | P4 (14-16) | P5 (16-21) | P6 (21-22) |

Process Completion Time Turnaround Time (TAT) Waiting Time (WT)
P1 4 4 - 1 = 3 3 - 3 = 0
P2 8 8 - 2 = 6 6 - 4 = 2
P3 14 14 - 3 = 11 11 - 6 = 5
P4 16 16 - 4 = 12 12 - 2 = 10
P5 21 21 - 5 = 16 16 - 5 = 11
P6 22 22 - 6 = 16 16 - 1 = 15
Average Turnaround Time :

(3 + 6 + 11 + 12 + 16 + 16) / 6 = 10.67 units

Average Waiting Time:

(0 + 2 + 5 + 10 + 11 + 15) / 6 = 7.17 units

Gantt Chart

| P1 (1-4) | P2 (4-8) | P3 (8-14) | P4 (14-16) | P5 (16-21) | P6 (21-22) |