Priority Scheduling

Priority Scheduling

  • It is a method of scheduling processes that is based on priority. Scheduler selects the task as per the priority.

  • the process with the highest priority should be carried out first where is the jobs with equal priorities are carried out on FCFS basis. smallest the integer highest the priority.

  • The SJF algorithm is simply a priority algorithm where the priority is inverse of predicted next CPU burst i.e. the larger the CPU burst the lower the priority and vice versa.

Preemptive priority scheduling

the tasks are mostly assigned with their priorities. in this scheduling, if the higher priority task comes, then the lower priority task holds for some time i.e. preempted out & CPU is given to higher priority task and the lower priority task resumes when higher priority task finishes.

Non preemptive priority scheduling

if the new process arrives with higher priority than the currently running process, then the incoming process is put at the head of the ready queue for next execution.

unlike primitive, it waits for completion of current running process i.e. once the execution of current process is over, new incoming process will be executed.

Starvation in priority scheduling

the process is considered blocked when it is ready to run but it has to wait for the CPU as some other process is running currently.

if the high priority processes take lots of CPU time, then the lower priority process may starve and will be blocked for indefinite time leading lower priority process to wait for long duration of time.

# FUNFACT :-

in 1973, when IBM 7904 machine was shut down, it was found that a low priority process which was submitted in 1967 and in this six years it had not been executed for once !!!!

Ageing as solution

to prevent starvation of any processes, we use the concept of aging, where we keep on increasing the priority of low priority processes based upon its waiting time.

aging involves gradually increasing the priority of processes that waits in a system for a long time.

Preemptive priority scheduling example :

TYPICAL PROCESS TABLE

HOW TO PREPARE GANTT CHART ??

  1. Draw a table containing 4 columns — time, process queue, execution & remaining burst time. (Process queue holds available processes based upon the time. & execution selects among the processes available in process queue.)

  2. Remember that serve the higher priority processes first and if the situation happens where we need to choose from same priority processes, selection is made on FCFS basis.

  3. For the gantt chart, Begin with time = 0,

  4. with each color shift, take an entry in gantt chart.

  5. End the Gantt chart with time = (last time stamp in the table + 1)

  6. cross-verify that ending gantt chart time equals the sum of burst time of every processes.

GANTT CHART FOR PRIORITY SCHEDULING

Os

Cpu Scheduling

Priority Scheduling