Professional Documents
Culture Documents
Preemptive
scheduling
Non
4. Terminates
CPU Scheduling
• Tasks are usually assigned with priorities
o Task (1) is running
o A higher priority task (2) has to run
o What will happen to task (1)?
• Types of scheduling
o Non-preemptive scheduling (Cooperative scheduling)
• running task (1) is executed till I/O request or terminated
(cannot be interrupted)
o Preemptive scheduling
• Task (1) is interrupted for some time and resumed later
when the priority task (2) has finished its execution.
CPU Scheduling
o Non-preemptive scheduling (Cooperative scheduling)
• does not allow a process running in kernel mode to be
preempted
• running task is executed till I/O request or terminated
(cannot be interrupted)
o Preemptive scheduling
• allows a process to be preempted while it is running in
kernel mode (but all data must be consistent).
• Task (1) is interrupted for some time and resumed later
when the priority task (2) has finished its execution.
Dispatcher
• Dispatcher module
o Gives control of CPU to selected process
o Should be as fast as possible, since it is invoked during
every process switch
• This involves:
o Switching context
o Switching to user mode
o Jumping to the proper location in the user program to
restart that program
2) Throughput maximize
o Number of completed process per unit time
3) Turnaround time
o Interval of time from submission till process completion
time
o Sum (waiting period to get to memory, waiting in ready
queue, CPU execution, I/O operation)
minimize
Scheduling Algorithm Optimization
Criteria
4) Waiting time
o Sum of time the process spent in the ready queue
minimize
In interactive system,
it is desirable to have a system with reasonable &
predictable response time
rather than a system that is faster on average but is highly
variable
First-Come, First-Served (FCFS)
Scheduling
0 24 27 30
0 3 6 30
P4 P1 P3 P2
0 3 9 16 24
• Average waiting time = (3 + 16 + 9 + 0) / 4 = 7
Example of SJF- Non Preemptive
Different Arrival Time
Process Arrival Time Burst Time
P1 0.0 6
P2 2.0 8
P3 4.0 7
P4 5.0 3
0 6 9 16 24
0 1 6 16 18 19
o Problem:
– Starvation or indefinite blocking
» low priority processes may never execute
• Solution
o Aging: as time progresses increase the priority of the
process
Round Robin (RR) Scheduling
• Steps:
o Each process gets a small unit of CPU time (time quantum),
usually 10-100 milliseconds.
o After this time has elapsed, the process is preempted and
added to the end of the ready queue.
• No process waits more than (n-1)q time units,
o for n processes in ready queue and time quantum is q,
• Performance is related to q
o If value is large ⇒ FIFO
o If value is small ⇒ overhead is too high
o q must be large with respect to context switching time
Example of RR with Time Quantum = 4
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
No of
context
switch
• In modern systems,
o Context switch < 10 microseconds
o q ranges from 10 to 100 milliseconds