CPU Scheduling Algorithm Demonstrator

A visual tool for A-level Computer Science students

Process Input

What is CPU Scheduling?

CPU Scheduling

CPU scheduling is the process of determining which process in the ready queue gets the CPU time. The main objective is to maximize CPU utilization and throughput while minimizing response time, waiting time, and turnaround time.

CPU scheduling determines which process runs at a certain time. The algorithms demonstrated here include:

  • First Come First Served (FCFS)

    First Come First Served (FCFS)

    FCFS is the simplest scheduling algorithm. Processes are executed in the order they arrive in the ready queue. It's non-preemptive, meaning once a process starts executing, it continues until it completes or blocks.

    Advantages: Simple to implement, fair in terms of arrival order.

    Disadvantages: Can lead to the "convoy effect" where short processes wait behind long ones, resulting in higher average waiting times.

  • Round Robin (RR)

    Round Robin (RR)

    Round Robin is a preemptive scheduling algorithm designed for time-sharing systems. Each process gets a small unit of CPU time (time quantum), and if it doesn't complete within that time, it's moved to the back of the ready queue.

    Advantages: Fair allocation of CPU time, good for time-sharing systems, responsive for short processes.

    Disadvantages: Performance depends heavily on the time quantum size. Too small causes excessive context switching, too large makes it similar to FCFS.

  • Shortest Job First (SJF)

    Shortest Job First (SJF)

    SJF selects the process with the smallest burst time first. It's non-preemptive in its basic form, meaning once a process starts, it runs to completion.

    Advantages: Provides minimum average waiting time among all scheduling algorithms when all processes arrive at the same time.

    Disadvantages: Difficult to implement as it requires knowing the burst time in advance. Can lead to starvation of longer processes if shorter ones keep arriving.

  • Shortest Remaining Time First (SRTF)

    Shortest Remaining Time First (SRTF)

    SRTF is the preemptive version of SJF. If a new process arrives with a burst time less than the remaining time of the current process, the current process is preempted.

    Advantages: Optimal average waiting time, responsive to short processes.

    Disadvantages: High overhead due to frequent context switching, potential starvation of longer processes, requires knowing burst times in advance.

Preemptive vs Non-preemptive

Preemptive vs Non-preemptive Scheduling

Preemptive scheduling allows the operating system to interrupt a running process and move it to the ready queue if a higher priority process arrives. This ensures better response times for high-priority or short processes.

Non-preemptive scheduling allows processes to run until they complete, block for I/O, or voluntarily yield the CPU. Once a process starts, it cannot be interrupted until it finishes its CPU burst.

Key differences:

  • Preemptive scheduling has higher context switching overhead
  • Non-preemptive scheduling is simpler to implement
  • Preemptive scheduling provides better response times
  • Non-preemptive scheduling can lead to priority inversion problems

Preemptive: Can interrupt running processes (RR, SRTF)
Non-preemptive: Processes run until completion (FCFS, SJF)