Add os/round-robin: Round Robin scheduler in C++ and C with Gantt chart, quantum sweep and captured output

This commit is contained in:
ankurm
2026-11-26 00:42:10 +05:30
parent f784f9b6ee
commit 9ed8479cec
24 changed files with 513 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env python3
"""Runs the earlier tick-loop program and rr.cpp on random workloads where every process
arrives at time 0 (the only case the old program can express) and compares waiting times."""
import random, subprocess, sys
random.seed(2015)
TRIALS, mismatches = 500, 0
for _ in range(TRIALS):
n = random.randint(1, 7)
bursts = [random.randint(1, 15) for _ in range(n)]
q = random.randint(1, 9)
old_in = f"{n}\n" + "\n".join(map(str, bursts)) + f"\n{q}\n"
new_in = f"{n}\n" + "\n".join(f"0 {b}" for b in bursts) + f"\n{q}\n"
old = subprocess.run(["build/old"], input=old_in, capture_output=True, text=True).stdout
new = subprocess.run(["build/rr"], input=new_in, capture_output=True, text=True).stdout
old_wt = [int(l.split()[2]) for l in old.split("PNo")[1].splitlines()[1:1 + n]]
new_wt = [int(l.split("\t")[5]) for l in new.splitlines()[3:3 + n]]
if old_wt != new_wt:
mismatches += 1
print(f"random workloads (all arrivals at 0, seed 2015): {TRIALS}")
print(f"waiting-time mismatches, legacy vs rr.cpp : {mismatches}")