CPU Scheduling
CPU Scheduling
CPU SCHEDULING
CPU Scheduler: -
Whenever the CPU becomes idle, the O.S must select one of the processes in the ready
queue to be executed. The short-term scheduler carries out the selection process. The
scheduler selects from among the processes in memory that are ready to execute and,
allocate the CPU to one of them.
When scheduling takes only under 1 and 4. Then such scheduling is known as
non-preemptive scheduling. Scheduling takes place under 2 & 3 is known as
preemptive scheduling.
The time it takes for the dispatcher to stop one process and
start another running is known as the dispatch latency
P1 24
P2 3
P3 3
Gantt Chart: -
P1 24
P2 3
P3 3
Gantt chart: -
It may be either preemptive or non preemptive. This algorithm is just a special case of
priority algorithm. SJF is non preemptive. It also a preemptive.
The preemptive SJF scheduling algorithm is some times called Shortest- remaining
time first (SRTF).
Priorities can be defined either internally or externally. Priority scheduling can be either
preemptive or non preemptive. When a process arrives at the ready queue, its priority is
compared with the priority of the currently running process.
✓ A preemptive priority-scheduling algorithm will preempt the CPU if the priority
of the newly arrived process is higher than the priority of the currently running
process.
A non-preemptive scheduling algorithm will simply put the new process at the head of
the ready queue.
✓ A major problem with priority scheduling algorithm is indefinite blocking or
starvation. A process that is ready to run but lacking the CPU can be considers
blocked, waiting for CPU. Here always the higher priority processes are
executed and lower priorities processes are wait long time for CPU.
✓ A solution to the problem of indefinite blockage of lower priority processes is
aging. Aging is technique of gradually increasing the priority of processes that
wait in the system for a long time.
Ex: - consider a multilevel feed back queue scheduler with three queues, numbered from
0 to 2. The scheduler first executes all processes in queue 0. Only when queue 0 is empty
will it execute processes in queue 1. Similarly, process that arrives for queue 1 will only
be executed if queue 0 is empty. A process that arrives for queue 1 will preempt a process
in queue 2.A process in queue 1 will in turn be preempted by a process arriving for queue
0. A process entering the ready queue is put in queue 0. A process in queue 0 is given a
time quantum of 8m.s. If it does not finish with in this time, it is moved to the tail of
queue of 1. If queue 0 is empty, the process at the head of queue 1 is given a quantum of
16 m.s. If it does not complete it is preempted and is put in to queue 2.
Processes in queue 2 are run on an FCFS basis, only when queues 0 and 1 are empty.
The multilevel feed back queue scheduler is defined by the following parameters.
1) The number of queues.
2) The scheduling algorithm for each queue.
3) The method used to determine when to upgrade a process to a higher priority
queue.
4) The method used to determine when to demote a process to a lower priority
queue.
5) The method used to determine which queue a process will enter when that
process needs services.