Chapter 3 CPU Sch (2)
Chapter 3 CPU Sch (2)
• Basic Concepts
• Scheduling Criteria
• Scheduling Algorithms
• Multiple-Processor Scheduling
• Real-Time Scheduling
• Algorithm Evaluation
2 2 3
0
4 7 0
P2 P3 P1
3
0 3 6
0
• Waiting time for P1 = 6; P2 = 0; P3 = 3
• Average waiting time: (6 + 0 + 3)/3 = 3
• Much better than previous case.
• Convoy effect short process behind long
process Operating System Concepts
Process BT AT
P1 7 0
P2 5 1
P3 2 2
P4 1 3
Process BT AT
P1 3 0
P2 5 1
P3 8 5
P4 4 5
Operating System Concepts
Process BT AT P
P1 3 0 4
P2 2 0 5
P3 8 3 3
P4 4 6 1
Process BT AT P
P1 ` 3 0 4
P2 5 1 3
P3 8 3 2
P4 4 5 1
Operating System Concepts
Shortest-Job-First (SJR) Scheduling
• Associate with each process the length of its
next CPU burst. Use these lengths to schedule
the process with the shortest time.
• 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 known
as the Shortest-Remaining-Time-First (SRTF).
BT AT P
P1 2 0 3
P2 2 3 2
P3 3 2 1
P4 4 3 2
/
/for calculating waiting time of each process
for(i=1; i<n; i++)
{
wt[i]= bt[i-1]+ wt[i-1];}
printf("Process ID Burst Time Waiting Time TurnAround
Time\n");
float twt=0.0;
float tat= 0.0;
for(i=0; i<n; i++)
{printf("%d\t\t", pid[i]);
printf("%d\t\t", bt[i]);
printf("%d\t\t", wt[i]); }
//calculating and printing turnaround time of each process
printf("%d\t\t", bt[i]+wt[i]);
printf("\n");
//for calculating total waiting time
twt += wt[i];
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
wt[0]=0;