Operating System: Bahria University, Islamabad
Operating System: Bahria University, Islamabad
CSL 320
Assignment-4
Student Name
MOHSIN KHAN
Enrolment No.
01-235181-027
Class and Section
BS-IT(5A)
Explain the following scheduling algorithm with examples in your own words.
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.
Non-Preemptive SJF
Preemptive SJF
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.
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.
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.
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.
P1 P2 P3 P4 P1 P3 P1 P1 P1
0 5 8 13 15 20 21 26 31
30
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
Example:
periodically performs the following job: senses the system status and actuates the system
according to its current status Control-Law Computation Sensor Actuator