Unit 4
Unit 4
1 SCHEDULING TYPES-
Scheduling Objectives,
CPU CPU and I/O Burst Cycles
SCHEDULING Pre-emptive, Non-preemptive
Scheduling, Scheduling Criteria
AND 4.2 TYPES of SCHEDULING Algorithms-
ALGORITHMS First come First Served (FCFS),
Shortest Job First (SJF)
(14 Marks) Shortest Remaining Time (SRTN)
Round Robin (RR)
Priority Scheduling ,
Multilevel Queue Scheduling
4.3 DEADLOCK-
System Models, Necessary Conditions
leading to Deadlocks, Deadlock
Handling-Preventions, Avoidance
SCHEDULING
SCHEDULING OBJECTIVES
All resources must be scheduled before they are used.
Scheduling is required for the CPU as well as input/output
devices.
I/O BURST
CPU BURST
CPU & I/ OBURST CYCLE EXAMPLE
load store
add store CPU Burst
read from file
load store
add store CPU Burst
read from file
wait for I/O I/O Burst
PRE-EMPTIVE & NON-PREMPTIVE
SCHEDULING
PRE-EMPTIVE SCHEDULING
Process is interrupted to stop its execution and allow
other process to start execution
Higher priority process get chance for execution early
Less number of process get executed
CPU UTILIZATION
THROUGHPUT
TURNAROUND TIME
WAITING TIME
RESPONSE TIME
SCHEDULING CRITERIA
1. CPU Utilization: CPU must be kept busy all the time so that it can be
utilized from 0 to 100%. The percentage of time during which CPU is busy
to execute processes is known as CPU utilization.
5. Response time:
The time difference between submission of job and the first
response from job, is known as response time.
TYPES OF SCHEDULING
ALGORITHMS
TYPES OF SCHEDULING ALGORITHMS
1 First Come First Serve (FCFS)
5 Priority Scheduling
P1 P2 P3 P4
0 8 12 21 26
• Turnaround Time for Process P1: (8-0)=8 Avg Turnaround Time
• Turnaround Time for Process P2: (12-1)=11 = (8+11+19+23) /4
• Turnaround Time for Process P3: (21-2)=19 = 61/4
• Turnaround Time for Process P4: (26-3)=23 = 15.25 ms
FCFS Example -2 Calculate
Process Arrival Burst time average
(ms) waiting time
P1 0 5 and
P2 1 15 turnaround
P3 2 25 time of above
P4 3 5 processes
using FCFS
GANTT CHART
P1 P2 P3 P4
0 5 20 45 50
• Waiting Time for Process P1: (0-0)=0 Avg Waiting Time = (0+4+18+42) /4
• Waiting Time for Process P2: (5-1)=4 =64/4
• Waiting Time for Process P3: (20-2)=18 = 16 ms
• Waiting Time for Process P4: (45-3)=42
FCFS Example -2 Calculate
Process Arrival Burst time average
(ms) waiting time
P1 0 5 and
P2 1 15 turnaround
P3 2 25 time of above
P4 3 5 processes
using FCFS
GANTT CHART TURNAROUND TIME= Completion Time- Arrival Time
P1 P2 P3 P4
0 5 20 45 50
• Turnaround Time for Process P1: (5-0)=5 Avg Turnaround Time
• Turnaround Time for Process P2: (20-1)=19 = (5+19+43+47) /4
• Turnaround Time for Process P3: (45-2)=43 = 114/4
• Turnaround Time for Process P4: (50-3)=47 = 28.5 ms
FCFS Example -3 (Practical 14)
Process Burst time (ms)
P1 21
P2 6
P3 3
P4 2
Consider the processes P1, P2, P3, P4 given in the below table, all processes arrives for
execution in the same order, with Arrival Time 0 and given Burst Time. Find using the
FCFS scheduling algorithm.
1. Turn around Time for each process
2. Waiting Time for Each Process
3. Average Turnaround Time
4. Average Waiting Time
FCFS Example -4 (Practical 14)
The jobs are scheduled for execution as follows:
Solve the problem by using FCFS and preemptive SJF
Find the average waiting time using GANTT chart
P1 P2 P4 P5 P3
0 7 11 17 25 35
P1 P2 P1 P4 P5 P3
0 1 5 11 17 25 35
P1 P2 P3 P1 P4
0 1 6 14 23 38
P1 P2 P3 P1 P4
0 1 6 14 23 38
P1 P2 P3 P4 P1 P2 P3 P1 P3 P3
0 4 8 12 16 20 23 27 30 34 37
P1 P2 P3 P4 P1 P2 P3 P1 P3 P3
0 4 8 12 16 20 23 27 30 34 37
P4 P3 P5 P1 P2
0 4 9 12 24 34
P4 P3 P5 P1 P2
0 4 9 12 24 34
TURNAROUND TIME= Completion Time- Arrival Time
Avg Turnaround Time =
• Turnaround Time for Process P1: 24 (24+34+9+4+12) /5
• Turnaround Time for Process P2: 34 =83/5
• Turnaround Time for Process P3: 9 = 16.6 ms
• Turnaround Time for Process P4: 4
• Turnaround Time for Process P5: 12
PRIORITY SCHEDULING Example 2
Process Burst time Priority
Calculate
(ms)
average
P1 10 3 waiting time of
P2 1 1 above
P3 2 3 processes
P4 1 4 using
P5 5 2 i) Nonpreem
ptive
GANTT CHART Priority
ii) RR
(Quantum
=1)
PRIORITY Scheduling- Preemptive Example
Process Arrival Burst Priority
Calculate
time (ms) average
P1 0 8 3 waiting time of
P2 1 1 1 above
P3 2 3 2 processes
GANTT CHART P4 3 2 3 using
P5 4 6 4 preemptive
priority
P1 P2 P3 P1 P4 P5
0 1 2 5 12 14 20
Example
• System,
• interactive,
• interactive editing,
Foreground Processes background Processes • Batch and
• Student processes queue.
P1 P2 P3 P4 P5 P7
READY QUEUE
MULTILEVEL QUEUE SCHEDULING WITH 5 QUEUES
AS PER PRIORITY
HIGHEST PRIORITY
SYSTEM PROCESSES
INTERACTIVE PROCESSES
BATCH PROCESSES
STUDENT PROCESSES
LOWEST PRIORITY
MULTILEVEL QUEUE SCHEDULING
• Consider all the processes in the system are divided into four
groups:
• System, Interactive, Interactive editing, Batch and Student
Processes Queue.
• Each queue contains processes.
• CPU is first scheduled for all queues on may be Priority, Total
burst time or Process type.
MULTILEVEL QUEUE SCHEDULING WITH 5 QUEUES
AS PER PRIORITY
HIGHEST PRIORITY
PR
SYSTEM PROCESSES
RR (Quantum: 8 ms)
INTERACTIVE PROCESSES
RR (Quantum: 10 ms)
INTERACTIVE EDITING PROCESSES
FCFS
BATCH PROCESSES
SJF
STUDENT PROCESSES
LOWEST PRIORITY
DEADLOCK
DEADLOCK
DEADLOCK
DEADLOCK
Allocated R1 REQUEST
P1
P2
REQUEST Allocated
R2
DEADLOCK
It occurs in multiprogramming system
Deadlock exists among a set of processes
if
Every process is waiting for an event
This event can be caused only by
another process in the set.
A waiting process never changes its
state
Coffman’s Conditions:
1. Mutual Exclusion
3. No Preemption
4. Circular Wait:
CONDITIONS FOR DEADLOCK
Coffman’s Conditions:
1. Mutual Exclusion: 2. Hold and Wait: A process holding at
least one resource & is waiting to acquire
Only one process at a time can use a additional resources held by other
resource & another process cannot processes
request for it.
P1 R1 X P2
CONDITIONS FOR DEADLOCK
Coffman’s Conditions: 4. Circular Wait: there exists a set {P0,
3. No Preemption: P1, …, Pn} of waiting processes such that
A resource can be released only P0 is waiting for a resource that is held by
voluntarily by the process P1, P1 is waiting for a resource that is held
holding it, after the process has by P2, …, Pn–1 is waiting for a resource
completed its task. It can not be that is held by Pn, and Pn is waiting for a
preempted. resource that is held by P0. This state of
the processes is circular wait state.
P2
Allocated R1 REQUEST
P1 P3
P1 P2
P4
DEADLOCK HANDLING METHODS
• Mutual Exclusion:
• If it is shareable resource, then we can break the mutual
exclusion (such as: Read-only file)
REQUEST Allocated
R3
DEADLOCK AVOIDANCE
Additional prior information regarding resources of
process required
Process must give information regarding resources at
starting
Bankers - safety algorithm used to avoid deadlock
Deadlock Avoidance
• If a system is in safe state no
deadlocks