0% found this document useful (0 votes)
8 views19 pages

First Come First Serve Scheduling: Process Queue Data Structure Batch Systems

The document discusses different scheduling algorithms including first come first serve, priority scheduling, and shortest job first. It provides details on how to calculate average waiting time and turnaround time for each algorithm. Examples and Gantt charts are given to illustrate the algorithms.

Uploaded by

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

First Come First Serve Scheduling: Process Queue Data Structure Batch Systems

The document discusses different scheduling algorithms including first come first serve, priority scheduling, and shortest job first. It provides details on how to calculate average waiting time and turnaround time for each algorithm. Examples and Gantt charts are given to illustrate the algorithms.

Uploaded by

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

First Come First Serve Scheduling

In the "First come first serve" scheduling algorithm, as the name suggests, the process
which arrives first, gets executed first, or we can say that the process which requests
the CPU first, gets the CPU allocated first.
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.
Calculating Average Waiting Time
For every scheduling algorithm, Average waiting time is a crucial parameter to
judge it's performance.
AWT or Average waiting time is the average of the waiting times of the
processes in the queue, waiting for the scheduler to pick them for execution.
Lower the Average Waiting Time, better the scheduling algorithm.
Consider the processes P1, P2, P3, P4 given in the below table, arrives for
execution in the same order, with Arrival Time 0, and given Burst Time, let's
find the average waiting time using the FCFS scheduling algorithm.
Gantt chart

P1p1 p2 p3 p4

WT p1=0
TAT p1=21 Wt p2=21
TAT p2=24 Wt p3=24
TAT p3=30 Wt p4=30
TAT p4=32 AWT=(0+21+24+30)/4=75/4=18.75
ATAT (21+24+30+32)/4=107/4=26.75
process Burst time
P1 8
P2 4
P3 9
p4 5
process Burst time
P1 8
P2 4
P3 9
p4 5

Gantt chart

P1p1 p2 p3 p4

12
0 8 21 26

Tat of p1=8
Wt for p1=0
Tat of p2=12
Wt for p2=8
Tat of p3=21
Wt for p3=12
Tat of p4=26
Wt for p4=21
Atat 67/4=16.75ms
Awt (41)/4=10.25ms
process Arrival Time Burst time
P1 0 8
P2 1 4
P3 2 9
p4 3 5

Tat of p1=8-0=8
Tat of p2=12-1=11
Wt for p1=0-0=0
Tat of p3=21-2=19
Wt for p2=8-1=7
Tat of p4=26-3=23
Wt for p3=12-2=10
Atat =61/4=15.25ms
Wt for p4=21-3=18
Awt =(0+7+10+18)=35/4=8.75ms
Priority Scheduling

• The SJF algorithm is a special case of the general priority scheduling algorithm.
• A priority is associated with each process, and the CPU is allocated to the process
with the highest priority. Equal-priority processes are scheduled in FCFS order.
• Priorities are generally indicated by some fixed range of numbers, such as 0 to 7
or 0 to 4,095. However, there is no general agreement on whether 0 is the highest
or lowest priority.
• Some systems use low numbers to represent low priority; others use low
numbers for high priority. This difference can lead to confusion.
• We assume that low numbers represent high priority.
• Priorities can be defined either internally or externally.
• Internally defined priorities use some measurable quantity or quantities to
compute the priority of a process. For example, time limits, memory
requirements, the number of open files, and the ratio of average I/O burst to
average CPU burst have been used in computing priorities.
• External priorities are set by criteria outside the operating system, such as the
importance of the process, the type and amount of funds being paid for computer
use, the department sponsoring the work, and other, often political, factors.
• Priority scheduling can be either preemptive or non preemptive.
• When a process arrives at the ready queue, its priority is compared with the priority
of the currently running process. A preemptive priority scheduling algorithm will
preempt the CPU if the priority of the newly arrived process is higher than the
priority of the currently running process.
• A non preemptive priority scheduling algorithm will simply put the new process at
the head of the ready queue.
• A major problem with priority scheduling algorithms is indefinite blocking, or
starvation. A process that is ready to run but waiting for the CPU can be considered
blocked. A priority scheduling algorithm can leave some low priority processes
waiting indefinitely.
• A solution to the problem of indefinite blockage of low-priority processes is aging.
Aging is a technique of gradually increasing the priority of processes that wait in the
system for a long time. For example, if priorities range from 127 (low) to 0 (high), we
could increase the priority of a waiting process by 1 every 15 minutes. Eventually,
even a process with an initial priority of 127 would have the highest priority in the
system and would be executed. In fact it would take no more than 32 hours for a
priority-127 process to age to a priority-O process.
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 3
P4 1 4
P5 5 2

Gantt chart

P2P2 P5 P1 P3 P4

19
0 1 6 16 18

WT of P1=6 Tat of P1=16


WT of P2=0 Tat of P2=1
WT of P3=16 P3=18
WT of P4=18 P4=19
WT of P5=1 P5=6
AWT=41/5=8.2 ATAT= 60/5=12
Jobs Burst Time Priority
J1 4 4
J2 6 1(Highest)
J3 2 3
J4 3 5(lowest)
Process Priority Arrival time CPU Burst time
P1 2 0 8
P2 3 1 4
P3 1 2 9
p4 4 3 5

Find out AWT, ATAT using preemptive and non preemptive scheduling algorithm

Non preemptive priority

P1 p3 p2 p4

0 8 17 21 26
Tat of p1=8-0=8
Wt of p1=0 Tat of p2=21-1=20
Wt of p2=17-1=16 Tat of p3=17-2=15
Wt of p3=8-2=6 Tat of p4=26-3=23
Wt 0f p4=21-3=18 Atat=66/4=16.5
Awt=40/4=10
Process Priority Arrival time CPU Burst time
P1 2 0 8-2=6
P2 3 1 4
P3 1 2 9
p4 4 3 5

Preemptive priority

P1p1 p3 p1 p2 p4

0 2 11 21 26
17
Wt of p1=(0-0)+(11-2)=9
Wt of p2=17-1=16 Tat of p1=17-0=17
Wt of p3=2-2=0 Tat of p2=21-1=20
Wt of p4=21-3=18 p3=11-2=9
Awt=43/4=10.75 p4=26-3=23
Atat=69/4=17.25
Find out AWT, ATAT using preemptive and non preemptive scheduling algorithm

job Burst time priority Arrival time


1 5-4=1 2 0
2 2 4 3
3 1 3 3
4 3 1 4

J1j1 j4 j1 j3 j2

0 4 7 8 9 11
Shortest Job First
In SJF scheduling, the process with the lowest burst time, among the list of
available processes in the ready queue, is going to be scheduled next.
However, it is very difficult to predict the burst time needed for a process
hence this algorithm is very difficult to implement in the system.
Advantages of SJF
Maximum throughput
Minimum average waiting and turnaround time
Disadvantages of SJF
May suffer with the problem of starvation
It is not implementable because the exact Burst time for a process can't be
known in advance.
It may cause starvation if shorter processes keep coming. This problem can be
solved using the concept of ageing.
Algorithm:

Sort all the process according to the arrival time.

Then select that process which has minimum arrival time and minimum Burst
time.

After completion of process make a pool of process which after till the
completion of previous process and select that process among the pool which is
having minimum Burst time.
Non preemptive and preemptive SJF

Jobs Burst Time Arrival Time


J1 4 0
J2 1 1
J3 2 2
J4 1 3

Non preemptive

J1j1 j2 j4 j3

0 4 5 6 8

AWT=2.25ms ATAT=4.25ms
Jobs Burst Time Arrival Time
J1 4-1=3 0
J2 1 1
J3 2-1=1 2
J4 1 3

Preemptive sjf

J1j1 j2 j3 j4 j3 j1

0 1 2 3 4 5 8
process AT BT
P1 0 8
P2 1 4
P3 2 9
p4 3 5

Preemptive sjf

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy