Chapter#02 - CPU Scheduling
Chapter#02 - CPU Scheduling
COURSE INSTRUCTOR:
COURSE:
COMPUTER APPLICATIONS (CS-353)
Objective
Scheduling Criteria
Scheduling Algorithms
Objectives
Waiting time – amount of time a process has been waiting in the ready
queue
Scheduling Algorithm Optimization Criteria
CPU utilization,
Throughput
Turnaround Time,
Waiting Time,
Response Time
First-Come, First-Served (FCFS) Scheduling
P1 P2 P3
0 24 27 30
P2 P3 P1
0 3 6 30
Associate with each process the length of its next CPU burst
Use these lengths to schedule the process with the shortest time
Two schemes:
Non-preemptive – 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
The difficulty is knowing the length of the next CPU request
Could ask the user
Example of SJF (non-preemptive)
P1 P3 P2 P4
0 3 7 8 12 16
Each process gets a small unit of CPU time (time quantum), usually 10-100
milliseconds. After this time has elapsed, the process is preempted and
added to the end of the ready queue.
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.
Performance
q large FIFO
q small q must be large with respect to context switch, otherwise
overhead is too high.
Example#01 of RR
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
Draw the Gantt Chart and also calculate average waiting time and average
turnaround time of the following algorithms using given table:
1. FCFS
2. SJF(Non-Preemptive)
Draw the Gantt Chart and also calculate average waiting time and average
turnaround time of the following algorithms using given table:
1. FCFS
2. SJF(Non-Preemptive)
3. Round Robin (Q=5)