07.Scheduling_Introduction
07.Scheduling_Introduction
Descheduled
Running Ready
Scheduled
Blocked
Job: current CPU burst (CPU time used in one stretch) of a process
Waiting Time: The amount of time a process has been waiting in the ready
queue. Waiting Time = (turnaround time - burst time)
Response time: The amount of time from when a request was submitted
until the first response is produced. Response Time = (the time at which a
process get the CPU first time - arrival time)
Fairness: All jobs get same amount of CPU over some time interval
Operating Systems by Dr. Praveen Kumar @ CSED, VNIT Nagpur 5
Exercise
Workload assumptions:
1. Each job runs for the same amount of time.
3. All jobs only use the CPU (i.e., they perform no I/O).
Gantt chart below : Illustrates how jobs are scheduled over time on a CPU
A B C
0 20 40 60 80 100 120
Time (Second)
𝟏𝟎 + 𝟐𝟎 + 𝟑𝟎
𝑨𝒗𝒆𝒓𝒂𝒈𝒆 𝒕𝒖𝒓𝒏𝒂𝒓𝒐𝒖𝒏𝒅 𝒕𝒊𝒎𝒆 = = 𝟐𝟎 𝒔𝒆𝒄
𝟑
Let’s relax assumption 1: Each job no longer runs for the same
amount of time.
0 20 40 60 80 100 120
Time (Second)
Run the shortest job first, then the next shortest, and so on
Non-preemptive scheduler
B C A
0 20 40 60 80 100 120
Time (Second)
𝟏𝟎 + 𝟐𝟎 + 𝟏𝟐𝟎
𝑨𝒗𝒆𝒓𝒂𝒈𝒆 𝒕𝒖𝒓𝒏𝒂𝒓𝒐𝒖𝒏𝒅 𝒕𝒊𝒎𝒆 = = 𝟓𝟎 𝒔𝒆𝒄
𝟑
SJF is non- preemptive, so short jobs can still get stuck behind long ones
[B,C arrive]
A B C
0 20 40 60 80 100 120
Time (Second)
Example:
A arrives at t=0 and needs to run for 100 seconds.
[B,C arrive]
A B C A
0 20 40 60 80 100 120
Time (Second)
Response time: The time from when the job arrives to the first time
it is scheduled.
STCF and related disciplines are not particularly good for response time.
0 5 10 15 20 25 30
Time (Second)
A B CA B CA B CA B CA B C
0+1+2
𝑇𝑎𝑣𝑒𝑟𝑎𝑔𝑒 𝑟𝑒𝑠𝑝𝑜𝑛𝑠𝑒 = = 1𝑠𝑒𝑐
3
0 5 10 15 20 25 30
Time (Second)
Example:
A and B need 50ms of CPU time each.
A A A A A B B B B B
CPU
Disk
A B A B A B A B A B Maximize the
CPU utilization by
CPU treating each 10ms
sub job of A as new
Disk job
The OS moves the process from blocked back to the ready state.