Priority Scheduling

 In priority scheduling , pick the job that has the highest priority. Every process is assigned a priority. Priority is an integer with range 1 to 10. The CPU is allocated to the process with highest priority. Processes with same priority are executed on basis of First Come First Served. 

Priority scheduling can be used in both preemptive and non preemptive mode. 

Preemptive

In preemptive mode, high priority job can remove a low priority job from CPU.


Process Name 

Arrival Time 

Burst Time 

Priority 

Process 1 

0 

10 

4 

Process 2 

2 

2 

2 

Process 3 

4 

1 

3 

Process 4 

6 

3 

5 

Process 5 

8 

5 

6 

  • Process 1 arrives at time 0 and start execution.
  • At time 2, process 2 arrives with higher priority so process 1 will be preempted and process 2 will execute.
  • At time 4 , process 3 arrives with higher priority than process 1 so it gets the CPU and completes its execution.
  • At  time 6, process 4 arrives with priority 4. Now there are two processes, process 1 and 4 . So process 1 will continue its execution.
  • At time 8, process 5 arrives with priority 5. process 1 is still high priority so it will complete its execution.
  • Process 1 release the CPU after completing its execution, so Process 4 will execute and than process 5 will execute.


Process 1 

Process 2 

Process 1 

Process 3 

Process 1 

Process 4 

Process 5 

0       2        

         4        

         5 

         6 

       13     

       16      

        21              


Average waiting time = (13+4+6+16+21) / 5
Average waiting time = 60 / 5
Average waiting time = 12

Non Preemptive

In non preemptive mode, highest priority process execute first. Once CPU is given a process it cannot be preempted.

Example

Process Name 

Arrival Time 

Burst Time 

Priority 

Process 1 

0 

9 

4 

Process 2 

0 

2 

2 

Process 3 

0 

3 

4 

Process 4 

0 

2 

5 

Process 5 

0 

5 

3 



  • All processes arrived at time 0. First of all process 2 will get the CPU because it has the highest priority 2.
  • Now process 5 will start execution it has the priority 3.
  • When process 5 will finish , then process 1 will start execution it has the priority 4.
  • When process 1 will finish , then process 3 will start execution it has the priority 3.
  • After process 3 execution , process 4 will start execution it has priority 5.
  • When process 4 will finish then it release the CPU.

Process 2 

Process 5 

Process 1 

Process 3 

Process 4 

0       2        

        7        

       16     

       19      

       21     


Average waiting time = (2+7+16+19+21) / 5
Average waiting time = 65 / 5
Average waiting time = 13

Shortest Job First Scheduling

Scheduling Algorithm





Comments

Post a Comment

If you have any doubts, please let me know

Popular Posts

Computer Abbreviation

Transport Layer

Introduction to Database

Types of database

Threads in operating system

Display devices

Shortcut keys of computer

History of Computer