/    /  OS – priority CPU Scheduling

Priority CPU Scheduling

 

In priority scheduling, the priority may or may not be set according to the CPU burst time. Instead, the scheduler selects tasks based on priority, which depends on time requirements, memory requirements, etc. 

The processes with higher priority are carried out first, processes with equal priority are executed on the basis of round-robin or FCFS method. 

 

Characteristics of priority scheduling:

 

  1. Processes are scheduled based on priority.
  2. If two processes are ready, it selects based on First Come First Serve.
  3. It is helpful in batch processing.
  4. A number is assigned to every process indicating their priority.
  5. If a process is running and a process with higher priority arrives, the current process will be preempted. 

 

Example of priority scheduling:

 

ProcessBurst TimeArrivalPriority
P1401
P2302
P3761
P44113
P52122

 

Step 1: Time=0, P1, and P2 arrives. As P1 has a higher priority than P2, P1 is executed. 

 

Step 2: Time=1, no new process arrives.

 

Step 3: Time=2, no new process arrives.

 

Step 4: Time=3, no new process arrives, P1 continues with its execution and P2 is in the waiting queue. 

 

Step 5: Time=4, P1 finishes its execution and P2 starts with the execution.

 

Step 6: Time=5, no new process arrive, therefore P2 continues with its execution.

 

Step 7: Time=6, P3 arrives, as P3 is of higher priority, it is executed while P2 is preempted. 

 

Step 8: Time=7, no new process arrives, therefore P3 continues with its execution.

 

Step 9: Time=8, no new process arrives.

 

Step 10: Time=9, no new process arrives. 

 

Step 11: Time=10, no new process arrives.

 

Step 12: Time=11, P4 arrives but as P3 has higher priority it continues its execution and P4 waits in the waiting queue.

 

Step 13: Time=12, P5 arrives. P3 has higher priority and hence continues with the execution.

 

Step 14: Time=13, P3 completes its execution. P2, P4, P5 are in the ready queue. P2 and P5 have equal priority but the arrival time of P2 is before P5, therefore P2 starts execution.

 

Step 15: Time=14, P2 finishes execution, and P5 starts with the execution as P5 is of higher priority than P4. 

 

Step 16: Time=15, P5 continues with execution.

 

Step 17: Time=20, P5 has completed execution. 

 

Step 18: We will calculate the average waiting time.

P1 = 0-0 = 0

P2 =4-0+ 7 =11

P3= 6-6=0

P4= 16-11=5

Average Waiting time = (0+11+0+5+2)/5 = 18/5= 3.6