In non-preemptive scheduling once a process has been allocated the CPU it runs uninterrupted until it finishes execution.
On the other hand, in preemptive schedule algorithms, the running process may be interrupted by a higher priority process in between its execution.
Whenever a process gets into ready state or the currently running finishes execution, the priority of the ready state process is checked against that of the running process.
If the priority of the ready process is more it is allowed to be allocated to the CPU.
Therefore, in these schemes, the CPU is allocated to the process with the highest priority all the time.
This gives rise to frequent context switching, which can become very costly in terms of CPU time wasted in switching. In the following sections we will explore some of such scheduling algorithms
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Operating system 30 preemptive scheduling
1. Operating System 30
Preemptive Scheduling
Prof Neeraj Bhargava
Vaibhav Khanna
Department of Computer Science
School of Engineering and Systems Sciences
Maharshi Dayanand Saraswati University Ajmer
2. Preemptive Scheduling
• In non-preemptive scheduling once a process has been allocated the CPU
it runs uninterrupted until it finishes execution.
• On the other hand, in preemptive schedule algorithms, the running
process may be interrupted by a higher priority process in between its
execution.
• Whenever a process gets into ready state or the currently running finishes
execution, the priority of the ready state process is checked against that of
the running process.
• If the priority of the ready process is more it is allowed to be allocated to
the CPU.
• Therefore, in these schemes, the CPU is allocated to the process with the
highest priority all the time.
• This gives rise to frequent context switching, which can become very
costly in terms of CPU time wasted in switching. In the following sections
we will explore some of such scheduling algorithms
3. Round Robin (RR)
• Each process gets a small unit of CPU time (time quantum
q), usually 10-100 milliseconds. After this time has
elapsed, the process is preempted and added to the end
of the ready queue.
• If there are n processes in the ready queue and the time
quantum is q, then each process gets 1/n of the CPU time
in chunks of at most q time units at once. No process
waits more than (n-1)q time units.
• Timer interrupts every quantum to schedule next process
• Performance
– q large FIFO
– q small q must be large with respect to context switch,
otherwise overhead is too high
4. Round Robin (RR)
• This algorithm is based on the principle that CPU must be
shared between each ready process.
• For this purpose, CPU time is divided into time-quantum or
time-slice.
• The ready processes are queued up in a circular queue.
• CPU is allocated to a process at the head of the queue.
• A context switching takes place whenever either the
running process exhausts its allocated time-quantum or
finishes its execution.
• At this time the running process is queued up at the tail of
the queue if it has not yet finished execution.
• The next process at the head of the ready queue is
allocated the CPU next.
5. Example of RR with Time Quantum = 4
Process Burst Time
P1 24
P2 3
P3 3
• The Gantt chart is:
• Typically, higher average turnaround than SJF, but better
response
• q should be large compared to context switch time
• q usually 10ms to 100ms, context switch < 10 usec
P P P
1 1 1
0 18 30
26
14
4 7 10 22
P2
P3
P1
P1
P1
8. Multilevel Queue scheduling
• Ready queue is partitioned into separate queues, eg:
– foreground (interactive)
– background (batch)
• Process permanently in a given queue
• Each queue has its own scheduling algorithm:
– foreground – RR
– background – FCFS
• Scheduling must be done between the queues:
– Fixed priority scheduling; (i.e., serve all from foreground
then from background). Possibility of starvation.
– Time slice – each queue gets a certain amount of CPU
time which it can schedule amongst its processes; i.e.,
80% to foreground in RR
– 20% to background in FCFS
9. Multilevel Queue scheduling
• Another class of scheduling algorithms has been
created for situations in which processes are easily
classified into different groups.
• For example, a common division is made between
foreground (interactive) processes and background
(batch) processes.
• These two types of processes have different response-
time requirements, and so might have different
scheduling needs.
• In addition foreground processes may have priority
(externally defined) over background processes.
10. Multilevel Queue scheduling
• A multilevel queue-scheduling algorithm partitions the
ready queue into several separate queues (Figure
Next).
• The processes are permanently assigned to one queue,
generally based on some property of the process, such
as memory size, process priority, or process type.
• Each queue has its own scheduling algorithm.
• For example, separate queues might be used for
foreground and background processes.
• The foreground queue might be scheduled by an RR
algorithm
12. Multilevel Feedback Queue
• A process can move between the various
queues; aging can be implemented this way
• Multilevel-feedback-queue scheduler defined by
the following parameters:
– number of queues
– scheduling algorithms for each queue
– method used to determine when to upgrade a
process
– method used to determine when to demote a
process
– method used to determine which queue a process
will enter when that process needs service
13. Multilevel Feedback Queue
• Normally, in a multilevel queue-scheduling
algorithm, processes are permanently assigned to
a queue on entry to the system (Figure Next).
• Processes do not move between queues.
• If there are separate queues for foreground and
background processes, for example, processes do
not move from one queue to the other, since
processes do not change their foreground or
background nature.
• This setup has the advantage of low scheduling
overhead, but is inflexible.
14. Example of Multilevel Feedback Queue
• Three queues:
– Q0 – RR with time quantum 8 milliseconds
– Q1 – RR time quantum 16 milliseconds
– Q2 – FCFS
• Scheduling
– A new job enters queue Q0 which is served
FCFS
• When it gains CPU, job receives 8
milliseconds
• If it does not finish in 8 milliseconds,
job is moved to queue Q1
– At Q1 job is again served FCFS and receives
16 additional milliseconds
• If it still does not complete, it is
preempted and moved to queue Q2
15. Assignment
• How is Preemptive Scheduling different from
Non-Preemptive Scheduling
• Explain Round Robin (RR) Scheduling
• Explain Multilevel Queue scheduling
• Explain Multilevel Feedback Queue