R
Rishtaara
Operating Systems Fundamentals
Lesson 3 of 8Article20 min

CPU Scheduling Algorithms

CPU Scheduling Algorithms

Scheduling goals

  • Minimize waiting time and turnaround time.
  • Maximize CPU utilization and throughput.
  • Prevent starvation and keep fairness.

Common algorithms

  • FCFS: simple, can cause convoy effect.
  • SJF/SRTF: efficient average wait, needs burst prediction.
  • Round Robin: good responsiveness with time quantum.
  • Priority scheduling: can starve low-priority tasks without aging.
Round Robin simulation sketch
type Job = { id: string; burst: number };

function roundRobin(queue: Job[], quantum: number): string[] {
  const timeline: string[] = [];
  const jobs = queue.map((j) => ({ ...j }));

  while (jobs.length) {
    const job = jobs.shift()!;
    const run = Math.min(job.burst, quantum);
    timeline.push(`${job.id} ran for ${run}`);
    job.burst -= run;
    if (job.burst > 0) jobs.push(job);
  }

  return timeline;
}