9.7.25

Priority Scheduling Algorithm

Priority Scheduling Algorithm

What is Priority Scheduling?

Priority Scheduling is a scheduling algorithm that assigns a priority to each process and executes the process with the highest priority first.

Types of Priority Scheduling

  • Preemptive Priority Scheduling: The operating system can preempt the currently running process if a higher-priority process arrives.
  • Non-Preemptive Priority Scheduling: The operating system does not preempt the currently running process, even if a higher-priority process arrives.

How Priority Scheduling Works

  • Assign a priority to each process.
  • Sort the processes in descending order of their priorities.
  • Execute the process with the highest priority first.

Example Calculation

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

Gantt Chart (Non-Preemptive)

Time Process
0-2 P4
2-3 P3
3-6 P1
6-9 P2

Calculation of Waiting Time and Turnaround Time

Process Arrival Time Burst Time Completion Time Turnaround Time Waiting Time
P4 0 2 2 2 0
P3 0 1 3 3 2
P1/td> 0 5 6 6 1
P2 0 3 9 9 6

Average Waiting Time and Turnaround Time

Average Waiting Time = (0 + 2 + 1 + 6) / 4 = 9 / 4 = 2.25

Average Turnaround Time = (2 + 3 + 6 + 9) / 4 = 20 / 4 = 5

No comments:

Post a Comment

Difference between File and Folder

10 Differences Between Files and Folders Definition: File: A collection of data or information stored on a computer. ...