Scheduling
Scheduling
•Throughput – Number of processes that complete their execution per in unit time
•Turnaround time – Total amount of time needed to execute a particular process
•Waiting time – amount of time a process has been waiting in the ready queue prior to
its execution
•Response time – amount of time it takes from when a request was submitted until the
first response is produced, not output (for time-sharing environment)
◦ Medium term scheduling: determines which process shall be allowed to compete for the CPU
◦ Short term scheduling: determines which ready process will be assigned the CPU when it next becomes
available and actually assign the CPU to this process
scheduling scheduling
short term
Suspended Ready Running Exit
medium term scheduling
scheduling
Selection Function: max(w), selects the process which is waiting in the ready
queue for maximum time.
Decision Mode : Non_preemptive
Throughput: Not emphasized
Response Time: May be high, especially if there is a large variance in the process
execution times.
Overhead: Minimum
Effect on Processes: Penalizes short and I/O bound processes.
Starvation: No
SCHOOL OF COMPUTER ENGINEERING & TECHNOLOGY
Computations :-
Completion Time: Time at which process completes its execution.
Turn Around Time: Time Difference between completion time and arrival time.
Turn Around Time = Completion Time – Arrival Time
Waiting Time(W.T): Time Difference between turn around time and burst time.
P1 P2 P3
0 24 27 30
P2 P3 P1
0 3 6 30
P1 P2 P3 P4
0 7 11 12 16
Average waiting time = (0 + 5 + 7 + 7)/4 = 4.75 TAT : P1 : 7,P2 :9 , P3 :8, P4 : 11
Average Turnaround Time = (7+9+8+11)/4=8.75
WT
, : P1 :0 , P2 :5, P3 :7, P4 :7
Two schemes:
• nonpreemptive – once CPU given to the process it cannot be preempted until completes its CPU
burst
• preemptive – if a new process arrives with CPU burst length less than remaining time of current
executing process, preempt. This scheme is know as the
Shortest-Remaining-Time-First (SRTF)
SJF is optimal – gives minimum average waiting time for a given set of processes
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
P1 P3 P2 P4
0 3 7 8 12 16
Waiting time :
P1 : 0, P3 : 3, P2 :6, P4:7 avg WT : 4
Turn around time :
P1 : 7, P3: 4, P2: 10, P4 :11 avg TAT :8
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16
If there are n processes in the ready queue and the time quantum is q, then each process
gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more
than (n-1)q time units.
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
P1 P2 P1 P3 P2 P4 P1 P4 P1
0 2 4 6 7 9 11 13 15 16
The CPU is allocated to the process with the highest priority (smallest integer highest
priority)
Problem Starvation – low priority processes may never execute
Solution Aging – as time progresses increase the priority of the process
In non-preemptive priority scheduling, once all the available processes are in the ready
queue, the scheduled process will run till the completion with no preemption.
In the preemptive priority scheduling, the process which is being executed can be
stopped at the arrival of a high priority process.
Some Formulas used to calculate turn around time and waiting time –
Turn Around Time = Completion Time – Arrival Time
Waiting Time = Turn Around Time – Burst Time
32 32 26
26 26 24
We can represent this example using GANTT chart as below –
26 32
1. Simplicity
2. Suitable for application with varying time and resource requirement
3. Process with high priority will execute first. It results in better response time.
Starvation
It is a situation in which the continuous arrival of higher priority process keeps the lowest priority process always in waiting state. The
waiting process will starve (in other words, the deadline of the waiting process will never meet). We can resolve the starvation problem in
the priority scheduling with the help of Aging technique.
Aging Technique
In Aging technique, the priority of every lower priority processes has to be increased after a fixed interval of time
•New process image has same process ID, same environment, and same file descriptor (because process is not replaced process image is replaced)
•The CPU stat and virtual memory is affected. Virtual memory mapping of the current process image is replaced by virtual memory of new process
image.
execl
execle
execlp
execv
execve
execvp