![priority scheduling](/wp-content/uploads/2022/12/PriorityScheduling.png)
Priority scheduling, the scheduler chooses the jobs to complete based on priority.
- Each Process has its own priority
- A priority number (integer) is associated with each process
- Out of all available process highest priority process gets the CPU
- If process with equal priority then use FCFS
Types of Priority Scheduling
Priority scheduling divided into two types:
- Premptive
- non premptive
Preemptive Scheduling
In anticipatory scheduling, the jobs are frequently allotted in accordance with their priority. It could be advantageous to complete the work with the higher priority first, even if the lower priority task is still in progress. After a brief break, the lower priority work will restart after the higher priority activity has finished.
Non-Preemptive Scheduling
In this type of scheduling strategy, the CPU has been allocated to a certain process. The CPU will become free when the activity using it changes context or stops. This method is the only one that functions on a range of hardware systems.
Priority Process
1 . Static – It doesn’t change throughout the execution of process
2. Dynamic – It changes after some interval of time
Characteristics of Priority Scheduling
- It is a CPU algorithm that assigns processes based on a priority.
- It is used in operating systems to carry out batch operations.
- First come, first served applies when two tasks of the same priority are READY.
- Each process in priority scheduling has a number given to it that represents the amount of priority.
- Higher priority is indicated by a lower number.
- The presently running process gets preempted in this sort of scheduling algorithm if a newer one comes that has a higher priority than the one that is now executing.
Example of Priority Scheduling
Consider following five processes P1 to P5. Each process has its unique priority, burst time without arrival time.
Process | Priority | Burst time |
---|---|---|
P1 | 3 | 10 |
P2 | 1 | 1 |
P3 | 4 | 2 |
P4 | 5 | 1 |
P5 | 2 | 5 |
Solution
Step 1: Take the high priority process first and add into the Gantt Chart. Here P2 process have highest priority. so P2 process executed first
Step 2: Take the next high priority process and add into the Gantt Chart. Here P5 process have next highest priority . So P5 process executed next.
Step 3: Similarly iterate all process with high priority and finally we can get the below Gantt Chart
Process | Priority | Burst Time (BT) | Waiting Time |
---|---|---|---|
P1 | 3 | 10 | 6 |
P2 | 1 | 1 | 0 |
P3 | 4 | 2 | 16 |
P4 | 5 | 1 | 18 |
P5 | 2 | 5 | 1 |
Waiting Time for process P1 = 6
Waiting Time for process P2 = 0
Waiting Time for process P3 = 16
Waiting Time for process P4 = 18
Waiting Time for process P5 = 1
Average Waiting Time = (6+0+16+18+1)/5
= 41/5
= 8.2
Problem in Priority Scheduling: Starvation – low priority process may never execute in the CPU
Solution for this problem is Aging
Aging -> as time progresses increases the priority of process
Advantages of priority scheduling algorithm
- Simple scheduling technique
- Processes are carried out according to priority, thus high priority tasks may be completed quickly, saving time.
- The relative importance of each process can be precisely defined using this method, which offers a good mechanism for doing so.
- Appropriate for applications with varying time and resource needs.
Disadvantages of priority scheduling algorithm
#aging #operating system #priority scheduling #scheduling algorithm
- Any low priority processes that are running at the time of a system crash are lost.
- Lower priority processes may starve and be delayed indefinitely if high priority processes use a lot of CPU time.
- Some low priority activities may be kept waiting for an eternity by this scheduling strategy.
- When a process is prepared to execute but must wait for the CPU because another process is already active, it will be blocked.
- The process in the waiting state may have to wait a very long time if new, higher priority processes keep entering the ready queue.