5 - OS Lecture
5 - OS Lecture
FIFO
SJF (Shortest Job First)
• This algorithm is based on the size of the
job.
• Take two jobs A and B.
A = 5 kilo bytes
B = 8 kilo bytes
• First the job A will be assigned processor
time after which B gets its turn.
Example (Shortest Job First)
Job # 1 2 3 4 55
Arrival time 0 2 4 6 88
Finish time
Service time 33 96 15
4 20
5 11
2
Response time 3 7 11 14 3
Service time 3 6 4 5 2
Wait time
Average response 0 time Job Job 57finishes9
1= 2(3+7+11+14+3)/5
finishes =17.6
Job 2Job 3Job
enters
enters 4JobJobs
enters Jobs
3, 4, 3,
5 enters 5 in4 in queue
queue
Throughput = 5/20
But to
But has has
Jobs
= 1/4
toJobs
finish Job
finish
3,Job Job
3,51
4 both4, 32all
5the isshortest
is queued thequeue
in shortest
Ave (RespTime/ServTime) = (1+7/6+11/4+14/5+3/2)/5 = 1.844
SJF
Round Robin . .
• Jobs are assigned processor time in a
circular method.
• For example take three jobs A, B, C. First
the job A is assigned to CPU then job B and
after B job C and then again A,B and C and
so on.
Example (Round Robin)
Job # 1 2 3 4 55
Arrival time 0 2 4 6 88
Finish time
Service time 43 18
6 17
4 20
5 15
2
Response time 4 16 13 14 7
Service time 3 6 4 5 2
WaitJ1
time
Assume
time
J2J3
time 1quantum
J2 enters
quantum
J2 J2J5
enters,
J4
time 10
enters,
enters,
time before
expires
J1
expires
J3 finishes
J2
time
expires
expires
then
J5
time
J4
time9J2
then
J1
expires
J3
time time
J4
expires
time time
expires
J5
time 9expires
expires
expires
finishes
expires 5
expires,
Average response
Queue:
Queue:
Queue: J1 J2,
Queue:
Queue:
J1
Queue:time
J1Queue:
Queue:
J1,
Queue:
J2,
J2
J3, =(J2
Queue:
J3
J2, (4+16+13+14+7)/5
J3,
Queue:
J2J4,
Queue:
J4,
was
J3,J2,
Queue:
J2,
J3 J5,
Queue:
J5,
J2
Queue:
J5,
inJ4, J4
Queue:
J4,
queue)
J3,
J4,
J3,
J2,
J3,
J2,
J3
J5,
J2,
J5,
J2
J4,
J5,
J4,
J5 =
J4,
J3,
J4
J3,10.8
J3
J2J2
J1J1 Switch
starts to Switch
continues
Switch J2Switch
Switch
Switch
to J1Switch
to to
J2Switch
to to
J3Switch
to J3Switch
J2Switch
J4Switch
to to
J2Switch
to
J5Switch
to
J4to
J3to
J2to
J5J4
Round
Robin
T=1
Example (Round Robin)
Job # 1 2 3 4 55
Arrival time 0 2 4 6 88
Finish time
Service time 53 17
6 13
4 20
5 15
2
Response time 5 15 9 14 7
Service time 3 6 4 5 2
Wait time
J2 enters,
J3J1 2then
finishes
enters,
J4 J3J5 J1
enters
time9time
enters
then
J2 time
expires
J2 5 finishes
expires
J4 time
time
expires
J3 expires
expires9 finishes
J5 finishes
J2 5 expires
J4 time
Average response
Queue:
Queue: J1 Queue:
J2,
Queue: time
J1
Queue:J3,
Queue:
J1, =J2,
Queue:
J2 (5+15+9+14+7)/5
Queue:
J3,
J2,J2J4, J3,
Queue:
J4J4,
J4, J5
Queue:
J3
J3,
J3,
Queue:
J5,
J5,
J5,
Queue:
J2
J2,
J2,
J2, =J410 J4
Queue:
J4
J4
J4
Switch
J1 starts Switch
toJ3
J2Switch
Switch toJ2
to continues
J3toSwitch
continues
J1SwitchJ2toSwitch
J4toSwitch
J3toSwitch
J5toJ4
J2to
Continues
J4
Round
Robin
T=2
Based on Priority. .
• In this method each job is assigned a
Priority.
• The higher Priority job is awarded favorable
treatment.
• Take two jobs A and B. Let the priority of A
be 5 and priority B be 7. Job B is assigned to
the processor before job A.
Distributed Operating System . .