124

Terms: Burst time (CPU time needed), Arrival time, Completion time, Turnaround time = Completion − Arrival, Waiting time = Turnaround − Burst, Response time = first run − arrival.

AlgorithmTypeIdeaProblem
FCFSNon-preemptiveFirst come, first servedConvoy effect (short jobs wait behind a long one)
SJFNon-preemptiveShortest burst first; minimum average waiting timeStarvation of long jobs; burst time must be known
SRTFPreemptive SJFShortest remaining time firstStarvation
PriorityEitherHighest priority firstStarvation → fixed by aging
Round RobinPreemptiveEach process gets a time quantum in turnToo small quantum = many context switches
Multilevel QueueEitherSeparate queues (system, interactive, batch)Rigid

Round Robin example with its waiting and turnaround times

Round Robin example with its waiting and turnaround times

FCFS average waiting time C++ 7 lines
// FCFS waiting time: each process waits for all bursts before it
int burst[] = {24, 3, 3}, n = 3, wait = 0, total = 0;
for (int i = 0; i < n; i++) {
    total += wait;
    wait += burst[i];
}
cout << "Average waiting = " << (double)total / n;   // (0 + 24 + 27) / 3 = 17