0% found this document useful (0 votes)
131 views

Operating System: Bahria University, Islamabad

The document describes an assignment for an Operating Systems course that requires students to explain six CPU scheduling algorithms: First-Come, First-Served (FCFS), Shortest-Job-First (SJF), Priority Scheduling, Round Robin (RR), Multilevel Queue Scheduling, and Multilevel Feedback Queue Scheduling. It provides examples and explanations of each algorithm. Students are instructed to complete the assignment individually and submit it by the due date to avoid penalties.

Uploaded by

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

Operating System: Bahria University, Islamabad

The document describes an assignment for an Operating Systems course that requires students to explain six CPU scheduling algorithms: First-Come, First-Served (FCFS), Shortest-Job-First (SJF), Priority Scheduling, Round Robin (RR), Multilevel Queue Scheduling, and Multilevel Feedback Queue Scheduling. It provides examples and explanations of each algorithm. Students are instructed to complete the assignment individually and submit it by the due date to avoid penalties.

Uploaded by

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

Operating System

CSL 320

Assignment-4

Student Name
MOHSIN KHAN
Enrolment No.
01-235181-027
Class and Section
BS-IT(5A)

Department of Computer Science


BAHRIA UNIVERSITY, ISLAMABAD
BS (IT)-5 (A)

Assignment #4 Subject: Operating System

Assignment Policy (Read Carefully)


 Cheating: Any form of cheating will not be tolerated.
 Collaboration: You can discuss the homework and the programming projects
with other students. However, the write up of the homework and the actual
coding must be your own. 
 Late submission: An assignment submitted:
o within 24 hours after its due will incur 15% penalty,
o after 24 hours and within 48 hours of its due date will incur 30%
penalty, and After 48 hours of its due date will not be graded    

Note: Upload the assignment on LMS and google classroom.

Explain the following scheduling algorithm with examples in your own words.

1. First-Come, First-Served (FCFS) Scheduling algorithm


2. Shortest-Job-First (SJF) Scheduling algorithm
3. Priority Scheduling algorithm
4. Round Robin (RR) Scheduling algorithm
5. Multilevel Queue Scheduling algorithm
6. Multilevel Feedback Queue Scheduling algorithm
7. Real Time Scheduling
1. First-Come, First-Served (FCFS) Scheduling algorithm
First Come First Serve (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. In this type of algorithm,
processes which requests the CPU first get the CPU allocation first. This is managed
with a FIFO queue. The full form of FCFS is First Come First Serve.

 First Come First Serve, is just like FIFO (First in First out) Queue data structure, where
the data element which is added to the queue first, is the one who leaves the queue
first.
 This is used in Batch Systems.
 It's easy to understand and implement programmatically, using a Queue data structure,
where a new process enters through the tail of the queue, and the scheduler selects
process from the head of the queue.
 A perfect real life example of FCFS scheduling is buying tickets at ticket counter.

Example of FCFS scheduling


 A real-life example of the FCFS method is buying a movie ticket on the ticket
counter. In this scheduling algorithm, a person is served according to the
queue manner. The person who arrives first in the queue first buys the ticket
and then the next one. This will continue until the last person in the queue
purchases the ticket. Using this algorithm, the CPU process works in a similar
manner.

2. Shortest-Job-First (SJF) Scheduling algorithm


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. The full form of
SJF is Shortest Job First.

There are basically two types of SJF methods:

 Non-Preemptive SJF
 Preemptive SJF

In non-preemptive scheduling, once the CPU cycle is allocated to process, the


process holds it till it reaches a waiting state or terminated.

In Preemptive SJF Scheduling, jobs are put into the ready queue as they come.
A process with shortest burst time begins execution. If a process with even a
shorter burst time arrives, the current process is removed or preempted from
execution, and the shorter job is allocated CPU cycle.

In the following example, there are five jobs named as P1, P2, P3, P4 and P5. Their
arrival time and burst time are given in the table below.

PID Arrival Time Burst Time Completion Time Turn Around Time Waiting Time

1 1 7 8 7 0

2 3 3 13 10 7

3 6 2 10 4 2

4 7 10 31 24 14

5 9 8 21 12 4

Since, No Process arrives at time 0 hence; there will be an empty slot in the Gantt chart from
time 0 to 1 (the time at which the first process arrives).

According to the algorithm, the OS schedules the process which is having the lowest burst time
among the available processes in the ready queue.

Till now, we have only one process in the ready queue hence the scheduler will schedule this to
the processor no matter what is its burst time.
This will be executed till 8 units of time. Till then we have three more processes arrived in the
ready queue hence the scheduler will choose the process with the lowest burst time.

Among the processes given in the table, P3 will be executed next since it is having the lowest
burst time among all the available processes.

So that's how the procedure will go on in shortest job first (SJF) scheduling algorithm.

   Avg Waiting Time = 27/5

3. Priority Scheduling algorithm


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.

Types of Priority 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.

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.

Example of Priority Scheduling Algorithm


Consider the below table fo processes with their respective CPU burst times and the priorities.
Process Burst Time Priority
P1 21 2
P2 3 1
P3 6 4
P4 2 3

The GANTT chart for following process based on priority Scheduling will be
P2 P1 P4 P3
0 3 24 26 32
The average waiting time will be, (0+3+24+26)/4=13.25 ms.

4. Round Robin (RR) Scheduling algorithm


The name of this algorithm comes from the round-robin principle, where each
person gets an equal share of something in turns. It is the oldest, simplest scheduling
algorithm, which is mostly used for multitasking.

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 scheduling algorithm is one of the most popular scheduling


algorithm which can actually be implemented in most of the operating systems.
This is the preemptive version of first come first serve scheduling. The Algorithm
focuses on Time Sharing. In this algorithm, every process gets executed in a cyclic
way. A certain time slice is defined in the system which is called time quantum.
Each process present in the ready queue is assigned the CPU for that time
quantum, if the execution of the process is completed during that time then the
process will terminate else the process will go back to the ready queue and waits
for the next turn to complete the execution.

Process Burst Time


P1 21
P2 3
P3 6
P4 2

The Gantt chart for round robin scheduling will be

P1 P2 P3 P4 P1 P3 P1 P1 P1

0 5 8 13 15 20 21 26 31
30

The average waiting time will be 11ms.

5. Multilevel Queue Scheduling algorithm


In the multilevel queue scheduling algorithm partition the ready queue has divided into
seven separate queues. Based on some priority of the process; like memory size,
process priority, or process type these processes are permanently assigned to one
queue. Each queue has its own scheduling algorithm. For example, some queues are
used for the foreground process and some for the background process.
The foreground queue can be scheduled by using a round-robin algorithm while the
background queue is scheduled by a first come first serve algorithm.

For example: A common division is made between foreground (or interactive)


processes and background (or 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 over
background processes.
A multi-level queue scheduling algorithm partitions the ready queue into several
separate queues. 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.
Consider below table of four processes under Multilevel queue scheduling. Queue
number denotes the queue of the process.
Process Arrival Time CPU Burst Time Queue Number
P1 0 4 1
P2 0 3 1
P3 0 8 2
P4 10 5 1

Priority of queue 1 is greater than queue 2. queue 1 uses Round Robin (Time
Quantum = 2) and queue 2 uses FCFS.
Below is the Gantt chart of the problem:

At starting both queues have process so process in queue 1 (P1, P2) runs first
(because of higher priority) in the round robin fashion and completes after 7 units
then process in queue 2 (P3) starts running (as there is no process in queue 1) but
while it is running P4 comes in queue 1 and interrupts P3 and start running for 5
second and after its completion P3 takes the CPU and completes its execution.
6. Multilevel Feedback Queue Scheduling algorithm

In a multilevel queue-scheduling algorithm, processes are permanently assigned


to a queue on entry to the system. Processes do not move between queues. This
setup has the advantage of low scheduling overhead, but the disadvantage of
being inflexible.
Multilevel feedback queue scheduling, however, allows a process to move
between queues. The idea is to separate processes with different CPU-burst
characteristics. If a process uses too much CPU time, it will be moved to a lower-
priority queue. Similarly, a process that waits too long in a lower-priority queue
may be moved to a higher-priority queue.
Example –
Consider a system which has a CPU bound process, which requires the burst time
of 40 seconds.The multilevel Feed Back Queue scheduling algorithm is used and
the queue time quantum ‘2’ seconds and in each level it is incremented by ‘5’
seconds. Then how many times the process will be interrupted and on which
queue the process will terminate the execution?
Solution –
Process P needs 40 Seconds for total execution.
At Queue 1 it is executed for 2 seconds and then interrupted and shifted to queue
2.
At Queue 2 it is executed for 7 seconds and then interrupted and shifted to queue
3.
At Queue 3 it is executed for 12 seconds and then interrupted and shifted to
queue 4.
At Queue 4 it is executed for 17 seconds and then interrupted and shifted to
queue 5.
At Queue 5 it executes for 2 seconds and then it completes.
Hence the process is interrupted 4 times and completes on queue 5.

7. Real Time Scheduling


Real time systems are the systems that carry real time tasks. These tasks need
to be performed immediately with cert degree of urgency. In particular, these
tasks are related to control of certain events (or) reacting to them. Real time
tasks can be classified as heard real-time tasks and soft real-time task. A hard
real time task must be performed on specified time which could otherwise
lead to huge losses. In a soft real-time tasks, a specified deadline can be
missed. This is because the task can be rescheduled (or) can be completed
after the specified time, in real-time systems, scheduler is considered as the
most important component which is typically a short-term task scheduler. The
main focus of this scheduler is to reduce the response time associated with
each of the associated processes instead of handling the deadline.

Example:

Digital control systems

periodically performs the following job: senses the system status and actuates the system
according to its current status Control-Law Computation Sensor Actuator

Real-Time System Example Multimedia Multi-media applications – periodically performs


the following job: reads, decompresses, and displays video and audio streams

You might also like