Skip to content

Simulates CPU scheduling algorithms (FCFS, SJF, Round Robin) in C, calculates process waiting and turnaround times, and prints per-time-unit execution.

Notifications You must be signed in to change notification settings

soh2970/C-cpu-scheduling-simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Assignment 4: CPU Scheduling Simulation

Overview

This C program simulates three classic CPU scheduling algorithms:

  • First-Come, First-Served (FCFS)
  • Shortest Job First (SJF)
  • Round Robin (RR)

It reads process data from an input file and calculates waiting time and turnaround time for each process according to the selected scheduling algorithm.

Functionality

  • Accepts a CSV input file where each line represents a process:

    P0,3
    P1,5
    ...
    

    Each line contains the process ID and its burst time.

  • Simulates the following algorithms:

    • -f for FCFS
    • -s for SJF
    • -r quantum for Round Robin with a user-specified time quantum
  • Outputs per-time-unit execution along with each process’s burst left, wait time, and turnaround time.

  • Displays final statistics:

    • Per-process wait and turnaround times
    • Total average wait and turnaround times

Compilation

gcc assignment-4.c -o assignment4

Usage

./assignment4 -f infile.csv       # First-Come, First-Served
./assignment4 -s infile.csv       # Shortest Job First
./assignment4 -r 2 infile.csv     # Round Robin with quantum 2

Sample Output

T0: P0 - Burst left 3, Wait time 0, Turnaround time 0
T1: P0 - Burst left 2, Wait time 0, Turnaround time 1
...
P0
Waiting time:     0
Turnaround time:  3

Total average waiting time:     2.5
Total average turnaround time:  4.0

Notes

  • Processes are assumed to arrive at time proportional to their process number (e.g., P0 at T0, P1 at T1).
  • Time quantum for RR must be a positive integer.
  • Output is printed to standard output.

License

This project is part of CS 3305A - Operating Systems at Western University. For academic use only.

About

Simulates CPU scheduling algorithms (FCFS, SJF, Round Robin) in C, calculates process waiting and turnaround times, and prints per-time-unit execution.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages