Priority (Non-Preemptive) Algorithm
Priority Scheduling is a method of scheduling processes that is based on priority. In this algorithm, the scheduler
selects the tasks to work as per the priority.
The processes with higher priority should be carried out first, whereas jobs with equal priorities are carried out on FCFS basis. Priority depends upon memory requirements, time requirements, etc.
In Priority (Non-Preemptive) scheduling method, the CPU has been allocated to a specific process. The process that keeps the CPU
busy, will release the CPU either by switching context or terminating.
Characteristics
- Priority scheduling is a non-preemptive algorithm and one of the most common scheduling algorithms in batch systems.
- Each process is assigned a priority. Process with highest priority is to be executed first and so on.
- Processes with same priority are executed on first come first served basis.
- Priority can be decided based on memory requirements, time requirements or any other resource requirement.
Advantages
- It is one of the simplest and easiest form of CPU Scheduling Algorithm.
- Process having high priority doesn't have to wait for a long time.
- It is used in the places where time varies eventually along with resources.
Disadvantages
- In this type of algorithm, process having highest priority compared to currently executing process have to wait till
execution ends
- Some low priority processes can be in waiting state for an indefinite time.
- On system crash, low priority processes shall not be scheduled.
- Resource Utilization in parallel is not possible here.
Example
Process |
Priority |
Arrival Time |
Burst Time |
P1 |
0(L) |
0 |
4 |
P2 |
4 |
1 |
5 |
P3 |
5 |
2 |
6 |
P4 |
10 |
3 |
7 |
P5 |
8 |
4 |
6 |
P6 |
17(H) |
7 |
5 |
P7 |
9 |
8 |
4 |
Working
- Step 0) Since at T = 0 only P1 has arrived, it will get executed first despite having the lowest priority
- Step 1) At T = 4 P1 has executed completely and the processes P2, P3, P4 and P5 have arrived
- Step 2) Out of processes P2, P3, P4 and P5, P4 has the highest priority hence it will get executed at T = 4
- Step 3) At T = 11 P4 has executed completely and the processes P2, P3, P5, P6 and P7 are in the waiting queue
- Step 4) Out of processes P2, P3, P5, P6 and P7, P6 has the highest priority hence it will get executed at T = 11
- Step 5) At T = 16 P6 has executed completely and the processes P2, P3, P5 and P7 are in the waiting queue
- Step 6) Out of processes P2, P3, P5 and P7, P7 has the highest priority hence it will get executed at T = 16
- Step 7) At T = 20 P7 has executed completely and the processes P2, P3 and P5 are in the waiting queue
- Step 8) Out of processes P2, P3 and P5, P5 has the highest priority hence it will get executed at T = 20
- Step 9) At T = 26 P5 has executed completely and the processes P2 and P3 are in the waiting queue
- Step 10) Out of processes P2 and P3, P3 has the highest priority hence it will get executed at T = 26
- Step 11) At T = 32 P3 has executed completely and the process P2 is in the waiting queue
- Step 12) Finally P2 will get executed at T = 32 and will get completely executed by T = 37
Gantt Chart
P1 |
P4 |
P6 |
P7 |
P5 |
P3 |
P2 |
0 - 4 |
4 - 11 |
11 - 16 |
16 - 20 |
20 - 26 |
26 - 32 |
32 - 37 |
Final Table
Process |
Priority |
Arrival Time |
Burst Time |
Completion Time |
Turn Around Time |
Waiting Time |
Response Time |
P1 |
0(L) |
0 |
4 |
4 |
4 |
0 |
0 |
P2 |
4 |
1 |
5 |
37 |
36 |
31 |
31 |
P3 |
5 |
2 |
6 |
32 |
30 |
24 |
24 |
P4 |
10 |
3 |
7 |
11 |
8 |
1 |
1 |
P5 |
8 |
4 |
6 |
26 |
22 |
16 |
16 |
P6 |
17(H) |
7 |
5 |
16 |
9 |
4 |
4 |
P7 |
9 |
8 |
4 |
20 |
12 |
8 |
8 |