0% found this document useful (0 votes)
0 views8 pages

OS UNIT-2 (Chapter 4, CPU Scheduling)

Chapter 4 of the document discusses CPU scheduling, outlining various scheduling criteria such as CPU utilization, throughput, turnaround time, waiting time, and response time. It details different scheduling algorithms including First Come First Serve, Shortest Job First, Priority Scheduling, Round Robin, Multi-Level Queue, and Multi-Level Feedback Queue, along with their advantages and disadvantages. Additionally, it covers multi-processor scheduling, processor affinity, load balancing, multi-core processors, and real-time CPU scheduling, distinguishing between hard and soft real-time systems.

Uploaded by

P Shashidhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views8 pages

OS UNIT-2 (Chapter 4, CPU Scheduling)

Chapter 4 of the document discusses CPU scheduling, outlining various scheduling criteria such as CPU utilization, throughput, turnaround time, waiting time, and response time. It details different scheduling algorithms including First Come First Serve, Shortest Job First, Priority Scheduling, Round Robin, Multi-Level Queue, and Multi-Level Feedback Queue, along with their advantages and disadvantages. Additionally, it covers multi-processor scheduling, processor affinity, load balancing, multi-core processors, and real-time CPU scheduling, distinguishing between hard and soft real-time systems.

Uploaded by

P Shashidhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Operating System Chapter 4[CPU Scheduling]

Scheduling Criteria :
CPU scheduling is the process of determining which process or task is to be executed by the
central processing unit (CPU) at any given time. It is an important component of modern
operating systems that allows multiple processes to run simultaneously on a single processor.
CPU Scheduling Criteria
There are some CPU scheduling criteria given below −
1. CPU Utilization
CPU utilization is used in CPU scheduling that measures the percentage of time the CPU is
busy processing a task. Keeping the CPU as busy as possible. CPU utilization may range from
0% to 100%.
2. Throughput: Throughput is the amount of work completed in a unit of time. Or Throughput
is the processes executed to number of jobs completed in a unit of time.
3. Turn Around Time: The interwell from the time of submission of a process to the time of
completion is called Turn Around Time.
Turn Around Time = Waiting Time + Execution Time.
4. Waiting Time: Sum of period spent in the ready queue is called waiting time.
Waiting Time = Turn Around Time – Burst Time.
5. Response Time : The time from submission of a request until the first response is produced
is called response time.
[
 Arrival Time : Time at which the process arrives in the ready queue.
 Completion Time : Time at which the process completes its execution.
 Burst Time : Time required by a process for CPU execution.

 Dispatcher is the module that gives control of the CPU to the process selected by
the short-term scheduler. This function involves:

 Switching context
 Switching to user mode
 Jumping to the proper location in the user program to restart that program from
where it left last time.

The dispatcher should be as fast as possible, given that it is invoked during every process
switch. The time taken by the dispatcher to stop one process and start another process is known
as the Dispatch Latency.

]
NOTE: To increase the system performance, the CPU Utilization and Throughput must be
increase. The waiting time, response time, turnaround time must be decrease.

Anuradha K N, Dept of BCA ,SDC, Tumkur.


Operating System Chapter 4[CPU Scheduling]

Scheduling Algorithm
CPU scheduling deals with the problem of deciding which of the processes in the ready queue
is to be allocated the CPU.
1. First Come First Serve Scheduling [FCFS].
2. Shortest Job First Scheduling [ SJFS].
3. Priority Scheduling.
4. Round Robin Scheduling.
5. Multi-Level Queue Scheduling.
6. Multiple Feedback Queue Scheduling.
1.First Come First Serve Scheduling [FCFS].
FCFS is an operating system scheduling algorithm that automatically executes queued
requests and processes in order of their arrival. It is the easiest and simplest CPU scheduling
algorithm.
The processes which requests the CPU first get the CPU allocation first. This is managed with
a FIFO queue.
As the process enters the ready queue, its PCB (Process Control Block) is linked with the tail
of the queue and, when the CPU becomes free, it should be assigned to the process at the
beginning of the queue.

Processes are dispatched accordingly to their arrival time on the queue.

Ex: Batch Processing System.

Advantages of FCFS

 The simplest form of a CPU scheduling algorithm.


 Easy to program.
 First come first served.
 There is no interrupts in the execution.

Disadvantages of FCFS

 It is a Non-Pre-emptive CPU scheduling algorithm, so after the process has been


allocated to the CPU, it will never release the CPU until it finishes executing.
 The Average Waiting Time is high.
 Short processes that are at the back of the queue have to wait for the long process at the
front to finish.
 Not an ideal technique for time-sharing systems.
 Because of its simplicity, FCFS is not very efficient.

Convoy Effect : If the CPU acquires the processes with higher burst time at the front end of
the ready queue then those processes which have lower burst time may get blocked. It means
that they may never get the CPU time if the job already in the execution has a very high burst
time. It is known as the convoy effect.

Anuradha K N, Dept of BCA ,SDC, Tumkur.


Operating System Chapter 4[CPU Scheduling]

The convoy effect is seen in the FCFS algorithm if the burst time of the first job entering the
ready queue of the CPU is the highest of all.

2. Shortest Job First Scheduling


Shortest Job First (SJF) is an algorithm in which the process having the smallest execution
time is chosen for the next execution. This scheduling method can be preemptive or non-
preemptive. It significantly reduces the average waiting time for other processes awaiting
execution.
If the 2 process have the same length then the FCFS scheduling is used.
There are basically two types of SJF methods:

Advantages :

 SJF is frequently used for long term scheduling.


 It reduces the average waiting time over FIFO (First in First Out) algorithm.
 SJF method gives the lowest average waiting time for a specific set of processes.

Disadvantages:

 Job completion time must be known earlier, but it is hard to predict.


 Requires knowledge of how long a process or job will run.
 It is hard to know the length of the upcoming CPU request.

3. Priority Scheduling:

Priority Scheduling is a method of scheduling processes that is based on priority. In this


algorithm, the scheduler selects the tasks to work as per the priority.

The processes with higher priority should be carried out first, whereas jobs with equal priorities
are carried out on a round-robin or FCFS basis. Priority depends upon memory requirements,
time requirements, etc.
Characteristics of Priority Scheduling

 A CPU algorithm that schedules processes based on priority.


 It used in Operating systems for performing batch processes.
 If two jobs having the same priority are READY, it works on a FIRST COME, FIRST
SERVED basis.
 In priority scheduling, a number is assigned to each process that indicates its priority
level.
 Lower the number, higher is the priority.
 In this type of scheduling algorithm, if a newer process arrives, that is having a higher
priority than the currently running process pre-empted.

Advantages of priority scheduling

 Easy to use scheduling method


 Processes are executed on the basis of priority so high priority does not need to wait for
long which saves time

Anuradha K N, Dept of BCA ,SDC, Tumkur.


Operating System Chapter 4[CPU Scheduling]

 This method provides a good mechanism where the relative important of each process
may be precisely defined.
 Suitable for applications with fluctuating time and resource requirements.

Disadvantages of priority scheduling

 If the system eventually crashes, all low priority processes get lost.
 If high priority processes take lots of CPU time, then the lower priority processes may
starve and will be postponed for an indefinite time.
 This scheduling algorithm may leave some low priority processes waiting indefinitely.
 A process will be blocked when it is ready to run but has to wait for the CPU because
some other process is running currently.

Starvation: In heavily loaded computer system the higher priority process can prevent low
priority process from available of CPU. This indefinite blocking of CPU for low priority
process is called Starvation.

Aging: A solution to the problem for indefinite blocking of low priority process is called
Aging.

Aging is a technique of gradually increasing the priority of the process that wait in the system
for a long time.

4. Round-Robin Scheduling

 In Round-robin scheduling, each ready task runs turn by turn only in a cyclic queue for
a limited time slice. This algorithm also offers starvation free execution of processes.
 Round robin is a pre-emptive algorithm
 The CPU is shifted to the next process after fixed interval time, which is called time
quantum/time slice.

Advantage of Round-robin Scheduling


Here, are pros/benefits of Round-robin scheduling method:

 It doesn’t face the issues of starvation or convoy effect.


 All the jobs get a fair allocation of CPU.
 It deals with all process without any priority
 If you know the total number of processes on the run queue, then you can also assume
the worst-case response time for the same process.
 This scheduling method does not depend upon burst time. That’s why it is easily
implementable on the system.
 Allows OS to use the Context switching method to save states of preempted processes.
 It gives the best performance in terms of average response time.

Disadvantages of Round-robin Scheduling

Anuradha K N, Dept of BCA ,SDC, Tumkur.


Operating System Chapter 4[CPU Scheduling]

 If slicing time of OS is low, the processor output will be reduced.


 Implementation is difficult.
 This method spends more time on context switching
 Its performance heavily depends on time quantum.
 Priorities cannot be set for the processes.
 Round-robin scheduling doesn’t give special priority to more important tasks.
 Finding a correct time quantum is a quite difficult task in this system.

5. Multi-Level Queue Scheduling.

The ready queue has been partitioned into seven different queues using the multilevel queue
scheduling technique. These processes are assigned to one queue based on their priority, such
as memory size, process priority, or type. The method for scheduling each queue is different.
Some queues are utilized for the foreground[Interactive] process, while others are used for the
background[non-interactive] process. The foreground queue may be scheduled using a round-
robin method, and the background queue can be scheduled using an FCFS strategy.

6. Multilevel Feedback Queue Scheduling.

It is used in the processes are permanently assign to a queue when they are entered the
system. It enables a process to switch between queues. If a process consumes too much
processor time, it will be switched to the lowest priority queue. A process waiting in a lower
priority queue for too long may be shifted to a higher priority queue. This type of aging prevents
starvation.

The parameters of the multilevel feedback queue scheduler are as follows:

1. The scheduling algorithm for every queue in the system.


2. The queues number in the system.
3. The method for determining when a queue should be demoted to a lower-priority queue.
4. When a process is upgraded to a higher-priority queue, this process determines when it
gets upgraded.

Anuradha K N, Dept of BCA ,SDC, Tumkur.


Operating System Chapter 4[CPU Scheduling]

5. The method for determining which processes will enter the queue and when those
processes will require service

Multiple Processor Scheduling:

A Multi-processor is a system that has more than one processor but shares the same
memory, bus, and input/output devices. In multi-processor scheduling, more than one
processors(CPUs) share the load to handle the execution of processes smoothly. The
scheduling process of a multi-processor is more complex than that of a single processor system.
The multiple CPUs in the system share a common bus, memory, and other I/O devices.

2 types of multiprocessor-
Homogenous – Systems in which processors are identical in terms of their functionality.
Heterogeneous - Systems in which processors are of different types.

Approaches to Multiple Processor Scheduling

 Symmetric Multiprocessing: In symmetric multi-processor scheduling, the processors


are self-scheduling. The scheduler for each processor checks the ready queue and
selects a process to execute. Each of the processors works on the same copy of the
operating system and communicates with each other. If one of the processors goes
down, the rest of the system keeps working.
 Asymmetric Multiprocessing: In asymmetric multi-processor scheduling, there is a
master server, and the rest of them are slave servers. The master server handles all the
scheduling processes and I/O processes, and the slave servers handle the users'
processes. If the master server goes down, the whole system comes to a halt. However,
if one of the slave servers goes down, the rest of the system keeps working.

Processor Affinity

A process has an affinity for a processor on which it runs. This is called processor
affinity.When a process runs on a processor, the data accessed by the process most recently is

Anuradha K N, Dept of BCA ,SDC, Tumkur.


Operating System Chapter 4[CPU Scheduling]

populated in the cache memory of this processor. The following data access calls by the process
are often satisfied by the cache memory.

There are two types of processor affinity.

 Soft Affinity: The system has a rule of trying to keep running a process on the same
processor but does not guarantee it. This is called soft affinity.
 Hard Affinity: The operating system will attempt to keep a process on a single
processor this situation is called hard affinity.

Load Balancing:

In a multi-processor system, all processors may not have the same workload. Some may have
a long ready queue, while others may be sitting idle. To solve this problem, load
balancing comes into the picture. Load Balancing is the phenomenon of distributing workload
so that the processors have an even workload in a symmetric multi-processor system.

 Push Migration: In push migration, a task routinely checks the load on each processor.
Some processors may have long queues while some are idle. If the workload is unevenly
distributed, it will extract the load from the overloaded processor and assign the load to
an idle or a less busy processor.
 Pull Migration: In pull migration, an idle processor will extract the load from an
overloaded processor itself.

Multi-Core Processors

A multi-core processor is a single computing component comprised of two or more CPUs


called cores. Each core has a register set to maintain its architectural state and thus appears to
the operating system as a separate physical processor. A processor register can hold an
instruction, address, etc. Since each core has a register set, the system behaves as a multi-
processor with each core as a processor.

Symmetric multiprocessing systems which use multi-core processors allow higher


performance at low energy.

Real Time CPU Scheduling :


A real-time system ia s computer that requires not only that the computing results be correct
but also that the results be produced within a specified deadline period period.

Two types of real time operating system

1. Hard real time system.


2. Soft real time system.

Hard real time system: it is used to execute and complete a given critical task within a
guaranteed period of time. The process is submitted for execution along with the amount of
time within which it must be completed.

Anuradha K N, Dept of BCA ,SDC, Tumkur.


Operating System Chapter 4[CPU Scheduling]

If the scheduler can guarantee that the process will be completed within a specified time,it
admits the process. Otherwise the scheduler rejects request ,it is calles resource reservation.

Resource reservation requires the scheduler to know exactly how long each operating system
function takes to perform.

Soft real time system: they are less restrictive. It simply providing that a critical real time
tasks gets priority over the others, and retains that priority until it completes. It has less timing
constraints and do not support dead line scheduling.

It causes unfair allocation of resource, leading to longer delays and starvation.

Difference between Pre-emptive and Non-Pre-emptive.

Anuradha K N, Dept of BCA ,SDC, Tumkur.

You might also like