You are on page 1of 15

cpu scheduling algorithm

CHAPTER 1

SYNOPSIS

Project Title

Cpu Scheduling Algorithm

1.2. Project Option

None

1.3. Internal Guide

Mr.Tannu R.R

1.4. Problem Statement

Cpu Scheduling Algorithm

Samarth Polytechnic, belhe 1|Page


cpu scheduling algorithm

CHAPTER 2

ABSTRACT

Developing CPU scheduling algorithms and understanding their impact in practice can
be difficult and time consuming due to the need to modify and test operating system kernel code
and measure the resulting performance on a consistent workload of real applications. As processor
is the important resource, CPU scheduling becomes very important in accomplishing the operating
system (OS) design goals. The intention should be allowed as many as possible running processes
at all time in order to make best use of CPU.
This paper presents a state diagram that depicts the comparative
study of various scheduling algorithms for a single CPU and shows which algorithm is best for the
particular situation. Using this representation, it becomes much easier to understand what is going
on inside the system and why a different set of processes is a candidate for the allocation of the
CPU at different time. The objective of the study is to analyze the high efficient CPU scheduler on
design of the high quality scheduling algorithms which suits the scheduling goals.

Samarth Polytechnic, belhe 2|Page


cpu scheduling algorithm

CHAPTER 3
INTRODUCTION

We will go through some basic information regarding CPU scheduling and some keywords
that are frequently used in CPU scheduling algorithms so that we can understand the different
algorithms better.

When the CPU is free, and its resources are available, then the CPU must
select a process from the ready queue and allocate resources for its execution. Selection is
performed with the help of CPU schedulers where the CPU scheduler selects a process from the
list of available processes (processes which are present in the ready queue).

Samarth Polytechnic, belhe 3|Page


cpu scheduling algorithm

CHAPTER 4
TYPES OF CPU SCHEDULING

Here are two kinds of Scheduling methods:

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.

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.

Samarth Polytechnic, belhe 4|Page


cpu scheduling algorithm

CHAPTER 5
IMPORTANT CPU SCHEDULING TERMINOLOGIES

• Burst Time/Execution Time: It is a time required by the process to complete execution.


It is also called running time.

• Arrival Time: when a process enters in a ready state

• Finish Time: when process complete and exit from a system

• Multiprogramming: A number of programs which can be present in memory at the same


time.

• Jobs: It is a type of program without any kind of user interaction.

• User: It is a kind of program having user interaction.

• Process: It is the reference that is used for both job and user.

• CPU/IO burst cycle: Characterizes process execution, which alternates between CPU and
I/O activity. CPU times are usually shorter than the time of I/O.

Samarth Polytechnic, belhe 5|Page


cpu scheduling algorithm

CHAPTER 6
CPU SCHEDULING CRITERIA

A CPU scheduling algorithm tries to maximize and minimize the following:

Maximize:
CPU utilization: CPU utilization is the main task in which the operating system needs to make
sure that CPU remains as busy as possible. It can range from 0 to 100 percent. However, for the
RTOS, it can be range from 40 percent for low-level and 90 percent for the high-level system.

Throughput: The number of processes that finish their execution per unit time is known
Throughput. So, when the CPU is busy executing the process, at that time, work is being done,
and the work completed per unit time is called Throughput.

Minimize:
Waiting time: Waiting time is an amount that specific process needs to wait in the ready queue.

Response time: It is an amount to time in which the request was submitted until the first response
is produced. the memory, waiting in the queue and, executing on the CPU.

Turnaround Time: Turnaround time is an amount of time to execute a specific process. It is the
calculation of the total time spent waiting to get into The period between the time of process
submission to the completion time is the turnaround time.

Samarth Polytechnic, belhe 6|Page


cpu scheduling algorithm

CHAPTER 7
TYPES OF CPU SCHEDULING ALGORITHM

There are mainly six types of process scheduling algorithms

1. First Come First Serve (FCFS)


2. Shortest-Job-First (SJF) Scheduling
3. Shortest Remaining Time
4. Priority Scheduling
5. Round Robin Scheduling
6. Multilevel Queue Scheduling

Samarth Polytechnic, belhe 7|Page


cpu scheduling algorithm

1.First Come First Serve


First Come First Serve is the full form of FCFS. It is the easiest and most simple CPU
scheduling algorithm. In this type of algorithm, the process which requests the CPU gets the CPU
allocation first. This scheduling method can be 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. So, when CPU becomes free, it should be assigned to the process at the beginning
of the queue.

We will understand it better using this example:

PROCESS BURST TIME WAITING TIME TURN AROUND TIME


P1 8 0 8
P2 3 8 11
P3 5 11 16
P4 3 16 19

Analysing the given proccesses, first the process P1 will be executed. Therefore, waiting time of
process P1 will be 0.
As, process P1 takes 8 units of time for completion, so waiting time for process P2 will be 8.

Likewise, waiting time of process P3 will be execution time of process P1 + execution time for
process P2, i.e. (8 + 3) units = 11 units. F
urthermore, for process P4 it will be the sum of execution times of P1, P2 and P3.

Advantages of FCFS :
• Simple

• Easy, useful and understandable

• First come, first served.


Disadvantages of FCFS :
• Because of non-preemptive scheduling, the process will continue to run untill it is
finished.

Samarth Polytechnic, belhe 8|Page


cpu scheduling algorithm

• As the scheduling is non-preemptive so short processes which are at end of ready


queue have to wait for a larger time making them starve leading to problem of
starvation.

• Throughput is not efficient.

2.Shortest Job First


SJF is a full form of (Shortest job first) is a scheduling algorithm in which the process with
the shortest execution time should be selected for execution next. This scheduling method can be
preemptive or non-preemptive. It significantly reduces the average waiting time for other processes
awaiting execution.

We will understand it better using this example:

PROCESS ARRIVAL TIME BURST TIME WAITING TIME TURN AROUND TIME

P1 1 7 0 7

P2 3 3 7 10

P3 6 2 2 4

P4 7 10 14 24

P5 9 8 4 12

Since arrival time of any process is not 0, there will be no execution or allocation of CPU from
time 0 to 1.
Following the algorithm further, process having the least burst time among the available
processes will be executed. Till now, we have only one process in the ready queue hence the
process will be scheduled no matter what the burst time is The process will be executed till 8 units
of time. Till then three more processes have arrived in the ready queue therefore, the process with
the lowest burst time will be choosen. P3 will be executed next as it has lowest burst time. So that's
how the process will go on in shortest job first (SJF) scheduling algorithm.

Advantages of SJF :
• Has minimum waiting time in comparison with other Scheduling Algorithms.
Disadvantages of SJF :
• Very difficult to predict the burst time of processes.

• Long running CPU bound jobs can starve.

Samarth Polytechnic, belhe 9|Page


cpu scheduling algorithm

3.Shortest Remaining Time


The full form of SRT is Shortest remaining time. It is also known as SJF preemptive scheduling.
In this method, the process will be allocated to the task, which is closest to its completion. This
method prevents a newer ready state process from holding the completion of an older process.

It is the preemptive mode of SJF CPU scheduling in which resources are allocated to processes
according to the shortest remaining time.

We will understand it better using this example:

PROCESS ARRIVAL TIME BURST TIME WAITING TIME TURN AROUND TIME

P1 0 8 12 20

P2 1 4 5 9

P3 2 2 0 2

P4 3 1 1 2

P5 4 3 6 9

P6 5 2 0 2

Starting with time t=0, the only available process is P1, as P1 being the only process
available so it is allocated with resources untill next process arrives.
At time t=1, the next process arrives in the ready queue. So, now there are two processes in
the ready queue. The remaining burst time for process P1 is now 7 units as it has been executed
for 1 unit till now. The burst time for P2 is 4,hence process P2 is provided with CPU resources for
the time being.
The next process P3 arrives at time t=2. Now the execution of P2 is stopped and the
processes are checked for least remaining burst time. Since the process P3 has burst time of 2
therefore it will be provided with CPU resources.
Process P4 arrives at t=3. Now the least burst time will be checked among the processes in
ready queue. P1 and P2 have 7 and 3 units as their burst time, also, burst time of both P3 and P4
is 1 unit, as remaining burst time being same, so the scheduling will be done according to their
arrival time. P3 arrives earlier therefore it will be provided with resources.
Process P5 arrives at time t=4. Now the remaining burst time of all the processes will be
compared and the process with least remaining burst time will be executed i.e. P4.
Process P6 arrives at time t=5, till now Process P4 has completed its execution. At last, 4 processes
are available, i.e. P1 (7), P2 (3), P5 (3) and P6 (2). The Burst time of P6 is the least, hence P6 is
scheduled.
Now, as all processes have arrived, so the scheduling will continue to be according to SJF
schedule

Samarth Polytechnic, belhe 10 | P a g e


cpu scheduling algorithm

4.Priority Based Scheduling


Priority scheduling is a method of scheduling processes based on priority. In this method, the
scheduler selects the tasks to work as per the priority.

Priority scheduling also helps OS to involve priority assignments. 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 can be decided based on memory requirements, time requirements,
etc.

We will understand it better using this example:

BURST ARRIVAL WAITING TURN AROUND


PROCESS PRIORITY TIME TIME TIME TIME

P1 2 1 0 0 1

P2 6 7 1 14 21

P3 3 3 2 0 3

P4 5 6 3 7 13

P5 4 5 4 1 6

P6 10 15 5 25 40

P7 9 8 6 16 24

At time 0, P1 arrives with the burst time of 1 units and priority 2. As no other process is
available so it will be provided with resources untill it finishes or next process arrives.
At time t=1, P2 arrives. As process P1 is complete and no other process is available so the process
P2 will be scheduled and will be provided with resources.
Process P3 arrives at time t=2, as the priority of P3 is higher, so the execution of P2 will be stopped
and P3 will be allocated with resources.
During the execution of P3, three more processes P4, P5 and P6 becomes available. Since,
all these three have the priority lower to the process in execution so PS can't preempt the process.

On the completion of process P3, process P5 will be executed as it is having maximum


priority. Meanwhile the execution of P5, all the processes got available in the ready queue.
Now the algorithm will behave as non-preemptive algorithm.
Hence now, once all the processes get available in the ready queue, the OS just took the process
with the highest priority and execute that process till completion.

Now process P4 will be scheduled and will be assigned resources untill completion. As
process P2 is having highest priority after the process P4 so, P2 will be scheduled next.

Samarth Polytechnic, belhe 11 | P a g e


cpu scheduling algorithm

P2 is assigned the CPU till the completion. As the remaining burst time is 6 units so process
P7 will be scheduled.

As only process P6 is remaining so process P6 will be executed at last.

Advantages of PS :
• The priority of the process can be selected first based on its memory consumption, etc.
Disadvantages of PS :
• Processes with same priority requires second scheduling algorithm.

• Starvation may occur as lower priority process keeps waiting for higher priority process.

5.Round-Robin Scheduling
Round robin is the oldest, simplest scheduling algorithm. The name of this algorithm comes from
the round-robin principle, where each person gets an equal share of something in turn. It is mostly
used for scheduling algorithms in multitasking. This algorithm method helps for starvation free
execution of processes.

We will understand it better using this example:

TIME QUANTUM = 2 (for given example)

PROCESS BURST TIME WAITING TIME TURN AROUND TIME

P1 8 10 18

P2 3 4 7

P3 5 14 19

P4 3 11 14

Select the first process and start executing the process (for quantum time only). Check if any other
process request has arrived.

In case any process arrives during the execution time of first process the process will be added to
circular queue. After execution of the process for the quantum time, check for the availability of
processes.

Samarth Polytechnic, belhe 12 | P a g e


cpu scheduling algorithm

If no process is in ready queue, then continue for the previous process. If not add current process
to the end of the ready queue.

Take next process from ready queue and start executing it(same rules). Repeat all above steps till
all processes are complete.

Advantages of RR :
• Priority is same for all processes as they are provided with same resources.

• Starvation does not occur because of its cyclic nature.


Disadvantages of RR :
• Throughput depends on quantum time.

• Processes can't be prioritised.

• Average waiting time can be bad.

6.Multiple-Level Queues Scheduling


This algorithm separates the ready queue into various separate queues. In this method, processes
are assigned to a queue based on a specific property of the process, like the process priority, size
of the memory, etc.

However, this is not an independent scheduling OS algorithm as it needs to use other types of
algorithms in order to schedule the jobs.

Characterstics of Multilevel Queue Scheduling :


• Each queue has it's own Scheduling algorithm. For each queue there can be same or
different scheduling algorithm.

• Processes are divided according to their type, memory consumption, etc.. in different
queues.
Advantages of Multilevel Queue :
• Has low scheduling overhead.
Disadvantages of Multilevel Queue :
• Can lead to starvation because running process can be preempted from low priority queue
when there is a new process in high priority queue.

• Processes can't switch queue after they are scheduled.

Samarth Polytechnic, belhe 13 | P a g e


cpu scheduling algorithm

CHAPTER 8

FUTURE WORK & RECOMMENDATION

As we end this stage of the project, we would like to recommend other researches in this field or
related to:
1- Add visual effects to the program which will get more attention for the user when implementing
an algorithm.
2- Add sound effects to the program to make it more attractive. 48
3- Use a more powerful programming like visual C++ or VB .NET , which has more modules and
facilities.
4- Use other CPU scheduling algorithms like multilevel queue and others and add it .

Samarth Polytechnic, belhe 14 | P a g e


cpu scheduling algorithm

CHAPTER 8
REFERENCE

http://www.homelanxtreme.com/wired-vs-wireless.htm

http://www.vicomsoft.com/knowledge/reference/wireless1.html#6
http://www.cert.org/tech_tips/home_networks.html#introduction
http://www.pcstats.com/articleview.cfm?articleID=1489
http://compnetworking.about.com/od/wirelesssecurity/
http://www.microsoft.com/hardware/broadbandnetworking/10_concept_what_is_wireless.mspx
http://www.infotel-systems.com/wireless%20networking%20outline.htm
http://www.homenethelp.com/web/diagram/index.asp

Samarth Polytechnic, belhe 15 | P a g e

You might also like