Unit 5 (CPU Scheduling)
Unit 5 (CPU Scheduling)
Operating System
(BCA 4th Sem)
Er. Preeti Sharma
(Assistant professor)
Scheduling
•Scheduling is an fundamental operating system function. It is a set of
policies and mechanisms built into the operating system that
governs the order in which the work to be done by computer
system.
CPU scheduling
•CPU scheduling is a process which allows one process to use the CPU
while the execution of another process is on hold(in waiting state)
due to unavailability of any resource like I/O etc, thereby making full
use of CPU. The aim of CPU scheduling is to make the system efficient,
fast and fair.
•Whenever the CPU becomes idle, the operating system must select
one of the processes in the ready queue to be executed. The
selection process is carried out by the short-term scheduler (or CPU
scheduler). The scheduler selects from among the processes in
memory that are ready to execute, and allocates the CPU to one
of them.
Types of CPU scheduling
• Preemptive Scheduling
•In Preemptive Scheduling, the tasks are mostly assigned with their priorities.
Sometimes it is important to run a task with a higher priority before another lower
priority task, even if the lower priority task is still running. The lower priority task
holds for some time and resumes when the higher priority task finishes its
execution.eg. SRTF, LRTF, ROUND ROBIN, PRIORITY BASED.
• Non-Preemptive Scheduling
•In this type of scheduling method, the CPU has been allocated to a specific
process. The process that keeps the CPU busy will release the CPU either
by
switching context or terminating. It is the only method that can be used
for
various hardware platforms. That's because it doesn't need special hardware (for
example, a timer) like preemptive scheduling.EG. FCFS
•SJF, LJF, HRRN,MULTILEVEL QUEUE, PRIORITY BASED.
Preemptive versus Non- preemptive
preemptive Non-preemptive
A scheduling discipline is preemptive if the CPU can A scheduling discipline is non- preemptive if once a
be taken away from a process after being allocated. process has been given the CPU, the CPU cannot be
taken away from that process.
In other words, even if the CPU has been allocated to a In other words, we can say in non preemptive
certain process, it can be snatched from his process scheduling once the CPU has been allocated to a
any time either due to time constraint or due to process, the process keeps the CPU until it release the
priority reason. CPU either by terminating or by switching to the
waiting stage.
Its costly as compared to non preemptive scheduling. Its not costly as compared to preemptive scheduling.
Context switching also involves overhead in
preemptive scheduling.
Higher priority jobs are processed before the lower In non-preemptive systems, short jobs are made to
priority jobs. wait by longer jobs.
When scheduling is Preemptive or
Non-Preemptive?
To determine if scheduling is preemptive or non-preemptive, consider
these four parameters:
•A process switches from the running to the waiting state.
•Specific process switches from the running state to the ready state.
•Specific process switches from the waiting state to the ready state.
•Process finished its execution and terminated.
• Only conditions 1 and 4 apply, the scheduling is called non-
preemptive.
• All other scheduling are preemptive.
Important CPU scheduling Terminologies
• Disadvantages
•It is inflexible as the processes can never change their
queue.
•Lower priority processes waits for indefinite time if some
higher priority queue are never becoming empty.
6. Multi-Level Feedback Queue Scheduling(MFQ)
•MFQ Scheduling is an enhancement of multi-level
queue scheduling. In this scheme, processes can
move between the different queues.
•The various processes are separated in different
queue on the basis of their CPU execution
time.
•If a process consumes a lot of CPU time, it is placed
into a lower priority queue.
•If a process waits too long in a lower priority queue
it is moved into higher priority queue.
•Each queue has given a different CPU time slice.
•If process does not finish within the time slice, it is
moved to the tail of next queue.
MFQ Scheduling
• Advantages
•More flexible
•Allow the processes to move between different queue
•A process that waits too long in lower priority queue may
be moved to a higher priority queue.
• Disadvantages
•Most complex scheduling algorithm
•Moving the processes around the queue produces
more CPU overhead.
Multiprocessor Scheduling
• Symmetric Multiprocessing System in which CPUs share system resources, and CPU
communicate to one another by sharing information in same memory space. This
is also known as Tightly Coupled Architecture.
• Parallel Processing System in which each CPU has its own resources and own memory
space. Thus CPU communicate externally using some type of network. This is known
as Loosely Coupled Architecture.
• In some type of multiprocessor system, classification is done on the basis of CPU used.
When Multiprocessor system uses different types of CPU, it is called as
Heterogeneous System whereas Homogeneous System uses identical CPUs.
•CPU scheduling in symmetric Multiprocessor systems is
almost similar to that of uniprocessor system. In such a
system, a single global ready queue is used by all the
CPUs.
•In addition to this, each CPU may have its own local
ready queue in order to avoid traffic.
•The processes from the global ready queue are
distributed to local queue.
•There are various way in which multiprocessor system
can be connected and operate. These are:
1. Separate system
2. Coordinated job scheduling
3. Master/Slave scheduling
4. Homogeneous scheduling
1. Separate system
• In this multiprocessor system, there are two or more separate system, each
with one processor, some main memory and peripheral devices.
This is just like having two or more separate computer system.
2. Coordinated job scheduling
• It is also known as loosely coupled multiprocessing, each processor is
associated with a separate system.
• When a job arrive it assign to any processor which is having less load.
3. Master/Slave scheduling
• There is one main processor called master and rest of all processor are
slaves.
• Master processor maintain the status of all processes and processor in the
system.
• Master processor selects a process to be run on available processor and
slave start execution, when process need I/O resources , slave
generate interrupt to the master processor and stop to await further
orders.
• It is not fair as it does not give equal importance to all processes.
4. Homogeneous scheduling
• In this system all processors are treated equally i.e. there is no master no
slave.
• Each processor uses the same scheduling algorithm to select the next
process to run.
Thread Scheduling
•A thread is an independent sequence of instruction
that can only be executed within the scope of a
process.
•A process can have more than one threads.
•There are two different methods to schedule
the execution of the thread:
1. The CPU is directly assigned to thread is called one-level
scheduling and same as CPU scheduling.
2. The CPU is first assigned to process and then the thread
within each process share the CPU for the time period
allocated to the process and is called two-level scheduling.
•Thread management and scheduling is done at
two different levels:
1. At Application level (User-level)
2. At Operating System level (Kernel-level)
• User Level Thread Scheduling ( Two-Level Scheduling)
•Each process gets the CPU for specific amount
of time.
•All the threads of a process are scheduled within this
amount of time.
•When there is no ready threads CPU is taken
away from that process.
•No preemption is necessary during
thread scheduling within a process.
Factor FSFC Round robin SJF SRT
Definition Process that Processes are Shortest process i.e. Process with
requests CPU first is allocated CPU turn with least burst time smallest estimated
allocated the CPU by turn one after gets CPU first. run time to
first the other. completion gets CPU
first
Decision mode Non- preemptive Non- preemptive Non- preemptive Non- preemptive
Throughput Not emphasized May be low if High High
quantum is too
small
Response time May be high Provides good Provides good Provides good
especially if there is response time for response time for response time
a large variance in short processes short processes
process execution
time.