Description
CS 370 Assignment 2: Schedulminator! Fall 2026 focuses on implementing a simulated Linux-style CPU scheduler using ANSI C. Students work with process priorities, nice values, time slices, preemption, and CPU/I/O bursts while managing startup, active, expired, and finished queues. The assignment also covers scheduling calculations, process transitions, and performance reporting.
Assignment Description
In Assignment 1, Shellminator introduced simulated processes. A command such as ls could appear to create a process, execute, terminate, and return control to the shell even though no real operating-system process was created. This assignment continues that idea. Instead of asking what command a process is running, we will ask a different question: When several processes want the CPU, which one should run? You will complete a simplified CPU scheduler. The scheduler is entirely a simulation: it does not create real processes, sleep, use timers, or ask the operating system to schedule anything. A simulated clock advances one tick at a time while your program moves Process structures among queues. The design is based on a simplified Linux-style scheduler. Processes arrive, wait in an active queue, execute CPU bursts, perform I/O, may be preempted, may exhaust a time slice and enter an expired queue, and eventually finish. From Shellminator to Schedulminator In the previous assignment, a process was primarily useful for making shell execution visible. In this assignment, the Process structure becomes more important. A simulated process now remembers information such as: • its PID and arrival time, • its nice value and scheduling priority, • its current time slice, • its CPU and I/O bursts, • how much CPU and I/O time it has accumulated, and • its current scheduling state. For example, imagine three processes: PID 0: ready PID 1: running PID 2: performing I/O Only PID 1 is using the simulated CPU. PID 0 is eligible to run but must wait. PID 2 is not currently competing for the CPU because it is completing an I/O burst. No real processes are created. These are C structures moving through an in-memory model of a scheduler. The Simulated CPU There is one CPU in this assignment. At most one PID may occupy it. 1 +—————-+ active queue —>| CPU |—> I/O queue | PID 2 | +—————-+ | +————> finished | +————> expired A CPU burst represents the amount of processor time a process needs before its next I/O operation or before it finishes. During each clock tick, a running process consumes one unit of its current CPU burst and one unit of its remaining time slice. The Queues The scheduler uses the following logical locations. Startup Queue Processes whose arrival time has not yet been reached remain here. Input order does not imply arrival order. Active Queue Processes that are ready to use the CPU wait here. The process with the lowest numeric priority value is preferred. When priorities are equal, use FIFO order. Expired Queue A runnable process that consumes its entire time slice moves here. Its dynamic priority and next time slice are recalculated. When the CPU and active queue are empty but expired is not, active and expired are exchanged. This represents the beginning of another scheduling epoch. I/O Queue A process whose CPU burst ends before the process itself is finished begins its next I/O burst. All processes in this queue make I/O progress during the same clock tick; there is no simulated contention for an I/O device. Finished Queue A process enters this queue after completing its final CPU burst. Keep finished processes in termination order because the final report uses that order. Nice Values, Priorities, and Time Slices A nice value is supplied in the input. Legal nice values range from −20 through +19. Larger nice values correspond to lower scheduling priority. Remember that a lower numeric priority value represents a stronger scheduling priority. The initial priority, which we will also call the original priority or static priority, is calculated from the nice value using 2 originalP riority = (int) nice + 20 39.0 × 30 + 0.5 + 105. The scheduler calculates a time slice from the current priority using timeSlice = (int) 1 − priority 140.0 × 290 + 0.5 + 10. The resulting time slice is a positive integer in the interval [10, 300]. After a process exhausts its time slice, its new, or dynamic, priority is priority = originalP riority + bonus. The bonus is an integer in the range [−5, +5] and depends upon how much CPU and I/O time the process has accumulated so far. Here, totalCPU is the total amount of time the process has spent using the simulated CPU and totalIO is the total amount of time it has spent performing simulated I/O. When totalCP U < totalIO, calculate the bonus using bonus = (int) 1 − totalCP U (double)totalIO × (−5) − 0.5 . Otherwise, calculate it using bonus = (int) 1 − totalIO (double)totalCP U × 5 + 0.5 . At the beginning of the simulation, a process may not yet have accumulated any CPU or I/O time. Your implementation must handle this initial case without dividing by zero. A process with no CPU/I/O history receives a neutral bonus of 0. Preemption Suppose PID 0 is currently running with priority 120: CPU: PID 0 (priority 120) PID 2 then becomes ready with priority 110. Because 110 is a stronger priority than 120, PID 2 preempts PID 0: [20] <2> Preempts Process 0 PID 0 returns to the active queue. It does not receive a new time slice merely because it was preempted. Its remaining CPU burst and remaining time slice are preserved. Equal priority does not cause preemption. 3 Input Input is read from standard input. Each process occupies one line: nice arrival cpu-count cpu-burst [io-burst cpu-burst]… The number of I/O bursts is always one fewer than the number of CPU bursts. The last burst on a process line is therefore always a CPU burst. A line containing *** ends the input. PIDs are assigned in input order beginning with PID 0. The input itself may be in any arrival order. For example: 0 0 2 30 15 20 5 5 1 25 -10 10 2 15 10 15 *** The first line describes PID 0. It has nice value 0, arrives at clock 0, and has two CPU bursts. Its execution pattern is: CPU 30 -> IO 15 -> CPU 20 Visible Scheduling Trace As with Shellminator, important simulated operating-system behavior is visible. Your output records significant events rather than printing every clock tick. Examples include: [0] <0> Enters ready queue (Priority: 120, Time Slice: 51) [0] <0> Enters the CPU [10] <2> Preempts Process 0 [25] <2> Moves to the IO Queue [35] <2> Finishes IO and moves to the Ready Queue [50] <2> Finishes and moves to the Finished Queue [1119] *** Queue Swap The trace helpers are provided. Your scheduling code determines when those events occur. Your Work The handout contains detailed comments for every function. Functions marked @student are your responsibility. Functions marked @provided are complete and should be studied rather than rewritten. The comments for student functions describe required behavior, constraints, and examples. They intentionally do not prescribe a particular loop structure or algorithm. More than one correct implementation is possible. PART 1: Scheduling Calculations Complete: 4 calculate_original_priority() calculate_bonus() calculate_dynamic_priority() calculate_time_slice() These functions translate nice values and observed process behavior into the numbers used by the scheduler. Do not hard-code a table of expected values. PART 2: Arrival and Ready-Queue Selection Complete: admit_arrivals() best_ready_index() At every clock tick, all processes whose arrival time has been reached must be moved out of startup. The input is not guaranteed to be sorted. When the CPU needs a process, choose the lowest numeric priority. FIFO order breaks ties. PART 3: Preemption Complete: preempt_if_needed() A ready process preempts the running process only when its numeric priority is strictly lower. Preserve the preempted process’s unfinished CPU burst and remaining time slice. PART 4: CPU and I/O Transitions Complete: handle_cpu_transition() handle_io_transitions() These functions decide where a process goes after CPU or I/O progress. A CPU burst ending takes precedence over a time slice ending on the same tick. A completed final CPU burst goes to finished. A non-final CPU burst goes to I/O. A process that has not completed its CPU burst but has exhausted its time slice goes to expired. When I/O finishes, the process either returns to active with its remaining time slice or enters expired with refreshed scheduling values. More than one I/O burst may finish during the same clock tick. PART 5: Performance Report Complete: print_report() For each process, in termination order, report: T urnaround = f inish − arrival W aiting = T urnaround − T otalCP U − T otalIO 5 CP UU tilization = T otalCP U T urnaround × 100. Also report total CPU time and total I/O time. CPU utilization for an individual process is displayed to one decimal place. After all processes are displayed, print average waiting time, average turnaround time, and average CPU utilization to three decimal places. Provided Scheduler Loop The simulation loop is supplied because the order of operations is part of the scheduler model. During one clock tick, the framework performs these operations in this order: 1. Admit processes whose arrival time has been reached. 2. Dispatch a process if the CPU is idle. 3. Check for priority preemption. 4. Perform one CPU tick. 5. Perform one I/O tick for every process doing I/O. 6. Handle the running process’s transition. 7. Handle all completed I/O bursts. 8. Stop if no scheduling work remains. 9. Swap active and expired if a new epoch is required. 10. Increment the simulated clock. Do not reorder these operations. A different order can produce different event times even when the individual functions appear reasonable. Points Your grade reflects how effectively your solution implements the scheduler within the assignment’s boundaries. Correct scheduling behavior matters more than matching the instructor’s internal implementation. See RUBRIC.txt for the complete 100-point breakdown and partial-credit guidelines. General Notes • Do not attempt to implement the entire scheduler at once. Begin with the priority calculations, then ready-queue selection, then transitions. • Compile and test frequently. • The supplied input files are examples, not an exhaustive test suite. Hidden tests will use different arrival orders, priorities, burst lengths, and ties. • Do not hard-code output from the sample inputs. • All declared variables must be used. • Use meaningful variable names, consistent indentation, and useful comments. • Output formatting matters. CodeGrade compares expected scheduling events and report values. 6 Restrictions • The assignment must be written in ANSI C and compile with the required command. • Do not create real processes or use process-related system calls. • Do not use fork(), exec(), wait(), pipe(), system(), popen(), threads, timers, or sleep functions. • Do not use dynamic memory allocation. • Do not add libraries or external dependencies beyond those already included in the handout. • Do not change required function names, parameter lists, or return types. • Do not replace the supplied simulation loop with a different scheduling order. Sample Build and Run % gcc – std = c90 – pedantic – Wall – Wextra sim_scheduler . c -o scheduler % ./ scheduler < input01 . txt Submission • Submit sim_scheduler.c to Canvas/CodeGrade by the deadline. • Your submission must compile in the designated grading environment. • Test the complete program before submission. • A program that depends on your local machine’s environment is not a valid submission. Agreement By submitting this assignment, you acknowledge the rules, requirements, and restrictions described above. Your submission must be your own work and must remain within the interfaces and facilities provided by the assignment. If any requirement is unclear, ask the instructor or GA before submitting
Solution Overview
The assignment covers implementing priority and time-slice calculations, dynamic priority bonuses, process arrivals, FIFO tie-breaking, and preemption. It also addresses CPU/I/O transitions, active-expired queue swapping, scheduling event traces, and performance reports calculating turnaround time, waiting time, and CPU utilization.



