Skip to content

Aria-Kalantari/CPU-Scheduling-Algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPU Scheduling Algorithms in C

A from-scratch C implementation of three classic CPU scheduling algorithms — FCFS, SJF (non-preemptive), and Round Robin — with a self-checking test harness (calculated vs. expected metrics) and a Dockerized build/run.

C Docker Tests


Overview

An operating-systems project that implements and validates the three foundational CPU scheduling policies in C. Each scheduler computes the standard performance metrics, and a dedicated test driver checks the calculated values against hand-derived expected values across multiple test cases — so correctness is demonstrated, not just asserted.

Algorithms

  1. FCFS — First Come First Served
  2. SJF — Shortest Job First (non-preemptive)
  3. Round Robin — time-sliced with a configurable quantum

Metrics computed for each

  • Average Turnaround Time (completion − arrival)
  • Average Waiting Time (turnaround − burst)
  • Average Response Time (start − arrival)

Why it's worth a look

  • Correctness is tested, not claimed. scheduler_test.c runs 8 test cases and asserts calculated metrics equal expected metrics for all three algorithms; a clean run prints ALL TESTS PASSED.
  • Clean separation of interface (scheduler.h), implementation (scheduler.c), and tests (scheduler_test.c).
  • Reproducible anywhere via Docker — no local toolchain required.

Build & run

With Docker (no local compiler needed):

docker build -t cpu-scheduler .
docker run --rm cpu-scheduler

Locally with gcc:

gcc scheduler.c scheduler_test.c -o scheduler_test
./scheduler_test

Either way you'll see calculated-vs-expected metrics per test case:

==== Test Case 1 ====
FCFS: Calculated: Turnaround: 15.00, Waiting: 7.33, Response: 7.33
      Expected:   Turnaround: 15.00, Waiting: 7.33, Response: 7.33
RR (Quantum = 4): Calculated: Turnaround: 19.33, Waiting: 11.67, Response: 3.00
      Expected:   Turnaround: 19.33, Waiting: 11.67, Response: 3.00
>>> Test Case 1 PASSED.
...
ALL TESTS PASSED.

Repository structure

CPU-Scheduling-Algorithms/
├── scheduler.h        # structs + scheduling function declarations
├── scheduler.c        # FCFS, SJF, Round Robin implementations
├── scheduler_test.c   # 8 test cases asserting calculated vs. expected metrics
└── Dockerfile         # containerized build & run

Skills demonstrated

Systems programming in C · operating-systems scheduling theory (FCFS / SJF / Round Robin) · turnaround / waiting / response-time analysis · test-driven validation with assertions · Docker containerization · clean header/implementation/test separation.


Author: Arya Kalantari · github.com/Aria-Kalantari

About

FCFS, SJF, and Round Robin CPU schedulers in C with a correctness test harness and a Dockerized build.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors