This repository contains C implementations of essential CPU scheduling algorithms. These algorithms play a crucial role in operating systems, efficiently managing the execution of processes on a CPU.
- First Come First Serve (FCFS)
- Shortest Job First (SJF)
- Preemptive Shortest Job First (SJF)
- Round Robin (RR)
- input.txt: Example input file showcasing process arrival times, burst times, and interrupt flags.
- output.txt: Example output file demonstrating the results of the CPU scheduling algorithms.
FCFS is a non-preemptive scheduling algorithm that executes processes in the order they arrive, without considering their burst times. It's simple and easy to implement but may lead to long waiting times for processes with long burst times.
SJF is a non-preemptive scheduling algorithm that executes the shortest job first. It minimizes average waiting time and turnaround time but requires knowledge of burst times in advance, which may not always be available.
Preemptive SJF is a preemptive version of the SJF algorithm. It switches to a shorter job if one arrives that requires less CPU time than the currently running job, reducing average waiting time and turnaround time further.
RR is a preemptive scheduling algorithm that assigns a fixed time unit (time quantum) to each process in a cyclic manner. It ensures fairness and prevents starvation but may result in higher overhead due to frequent context switches.
To run the code, compile cpu_scheduling.c
using a C compiler. Ensure to provide appropriate input in input.txt
, where process arrival times, burst times, and interrupt flags are specified. The output will be written to output.txt
.
-
Compile the code using a C compiler (e.g., gcc): gcc cpu_scheduling.c -o cpu_scheduling
-
Run the executable file: cpu_scheduling
To test the code, follow these steps:
- Create test cases with different sets of input data, considering various scenarios and edge cases.
- Run the code with each test case and compare the output against expected results.
- Analyze the output to ensure that the scheduling algorithms function correctly under different conditions.
The code for CPU scheduling algorithms is based on concepts from operating systems textbooks and online resources.