Professional Documents
Culture Documents
Dr Sudipta Saha
proc file system in Linux
/dev
/proc -
ls -ltr /proc/7494
directory description
• Multi-processor –
• More processes can run at the same time
CPU Utilization
Waiting time
Response Time
Scheduling criteria
CPU Utilization
Sum of the periods that the process spends in the ready queue
Scheduler – assigns the CPU – once the process gets the CPU –
the time it takes – So, how fast the process can be assigned with
the CPU – Should not be waiting long in the ready queue
A process may create some results very fast and then continue with the other results
The time from the submission of a request until the first response is produced is called
response time
Time it takes to start responding –does not include the time to output the response
Turn around time is limited by the speed of the output device – which is not true for
response time
FCFS – First Come First Serve
Scheduling
• The simplest one
• Whoever comes first – will be given first
• Fair
• Simple to understand and simple to implement
• A FIFO queue is enough
• Example
P1 P2 P3
24 27 30
0
• P2, P3, P1
P2 P3 P1
0 3 6 30
Convoy effect
FCFS Example
• Calculate the average waiting time and average
turn around time in the following scenario – if FCFS
scheduling is followed
Process ID Arrival Time Burst time (ms)
P1 4 5
P2 6 4
P3 0 3
P4 6 2
P5 5 4
FCFS example
• First create the Gantt chart
0 3 4 9 13 17 19
P3 P1 P5 P2 P4
FCFS example
• First create the Gantt chart
Process ID Arrival Time Burst time
P1 4 5
P2 6 4
P3 0 3
P4 6 2
P5 5 4
0 3 4 9 13 17 19
P3 Idle time P1 P5 P2 P4
FCFS - example
Turn around time = Completion time – Arrival time
0 3 9 16 24
P4 P1 P3 P2
Example - SJF
Average waiting time = (3 + 16 + 9 + 0)/4 = 7 ms
0 3 9 16 24
P4 P1 P3 P2
Process ID Burst time
(ms) The same set of process will
P1 6 have an average waiting
P2 8 time of 10.25 ms in case of
P3 7 FCFS scheduling algorithms
P4 3
Why ?
0
P1 arrives
first, but it
has high
burst time
P1
Process ID Arrival time Burst time
P1 0 8 (should be 7)
P2 1 4
P3 2 9
P4 3 5
0 1
P2 arrives having
lesser burst time
than P1
P1 P2
Process ID Arrival time Burst time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
0 1
P1 P2
0 1
P1 P2
0 1 5
P1 P2
0 1 5
P1 P2
After completion of P2 ie at 5 ms
So P4 is executed
Process ID Arrival time Burst time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
0 1 5 10
P1 P2 P4
P4 executes from 5 to 10
So P1 is executed next
Process ID Arrival time Burst time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
0 1 5 10 17
P1 P2 P4 P1
P1 executes from 10 to 17
So P3 is executed next
Process ID Arrival time Burst time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
0 1 5 10 17 26
P1 P2 P4 P1 P3
P3 executes from 17 to 26
0 1 5 10 17 26
P1 P2 P4 P1 P3
P1 P2 P4 P1 P3
Waiting time =
Total waiting time
Calculate the average – No of ms process executed
– Arrival Time
waiting time
Process ID Arrival time Burst Waiting time
time
P1 0 8 10 – 1 – 0 = 9 ms
P2 1 4 1 – 0 – 1 = 0 ms
P3 2 9 17 – 0 – 2 = 15 ms
P4 3 5 5 – 0 – 3 = 2 ms
0 1 5 10 17 26
P1 P2 P4 P1 P3
In preemptive version of SJF
scheduling algorithm -
GANTT Chart
0 2 6 12 17 27
P1 P2 P3 P4 P1
Waiting time =
Total waiting time
Calculate the average – No of ms process executed
– Arrival Time
waiting time
Process ID Arrival time Burst Waiting time
time
P1 0 12 17 – 2 – 0 = 15 ms
P2 2 4 2 – 0 – 2 = 0 ms
P3 3 6 6 – 0 – 3 = 3 ms
P4 8 5 12 – 0 – 8 = 4 ms
0 2 6 12 17 27
P1 P2 P3 P4 P1
Priority Scheduling
• There is a priority with each process
• CPU would allocate the process having the highest
priority
• If equal priority – FCFS is applied
0 1 6 16 18 19
P2 P5 P1 P3 P4
Average waiting time
Process ID Burst time Priority Waiting time
P1 10 3 6 ms
P2 1 1 0 ms
P3 2 4 16 ms
P4 1 5 18 ms
P5 5 2 1 ms
0 1 6 16 18 19
P2 P5 P1 P3 P4
Problems with priority scheduling
• The major problem is indefinite blocking – starvation
P4
P6
P5
Round Robin Scheduling
• A queue is maintained
• CPU scheduler selects the head of the queue
• 1st process starts and a timer starts for one
quantum
• When the timer goes off – The scheduler takes the
next entry – again executes for one quantum
• There are two prossibilities-
Round Robin Scheduling
• When a process gets the process – but the burst
time is less than the time quantum –
• Process will itself release the CPU
• When a process gets the process – the burst time is
more than the quantum –
• The timer will trigger – interrupt to the OS
• Context switch will happen
• Current context is saved
• How it can be implemented ?? CPU scheduler does
not move around the queue – rather head entry is
appended to the tail ….
Round Robin Scheduling
Process ID Burst time
P1 24
P2 3
P3 3
0 4 7 10 14 18 22 26 30
P1 P2 P3 P1 P1 P1 P1 P1
Turn around time and
waiting time
Process ID Burst time
P1 24
P2 3
P3 3
0 4 7 10 14 18 22 26 30
P1 P2 P3 P1 P1 P1 P1 P1
Turn around time and
waiting time
Process ID Completion time Turn around time Waiting time
P1 30 30 – 0 = 30 30-24 = 6
P2 7 7–0=7 7–3=4
P3 10 10 – 0 = 10 10 – 3 = 7
0 4 7 10 14 18 22 26 30
P1 P2 P3 P1 P1 P1 P1 P1
Waiting time
• Waiting time =
Last start time
- Arrival Time
- (Preemption number X Time quantum)
Process ID Completion time Turn around time Waiting time
P1 30 26 – 0 – 5X4 = 6
P2 7 4 – 0 – (0 X 4) =4
P3 10 7 – 0 – (0 X 4) = 7
Multilevel Queue Scheduling
• Scheduling among group of processes
System processes
Interactive processes
Batch processes
Student processes
Lowest priority
An example of a multi-level queue scheduling
algorithm with five queues -
Highest priority System processes
System processes
have the highest
Interactive processes
Lowest priority
Multilevel Feedback Queue
Scheduling
• Its defined by the following properties
• Number of queues
• Scheduling algorithm for each queue
• The method used to determine when to upgrade a
process from lower priority queue to higher priority
queue
• The method to determine when a process is to be
downgraded from higher priority queue to lower priority
queue
• When a process is moved – where to go – how many
step down or how many step up – ie to which of the
higher or lower priority queue
Types of Schedulers
• Their main task is to select the jobs to be submitted
into the system and to decide which process to run.
• Long-Term Scheduler
• Short-Term Scheduler
• Medium-Term Scheduler
Long Term Scheduler
• Job scheduler.
Scheduled / dispatched
Created Complete
Termin
New Ready Running
ated
Priority / Time
Suspend
I/O done
I/O
Resume Wait/
block
Suspended
ready Suspend
Resume