This is a C program that implements various CPU scheduling algorithms commonly studied in Operating Systems. The program provides a menu-driven interface to demonstrate the working of different scheduling algorithms with visualization through Gantt charts.
-
Implementation of 4 CPU scheduling algorithms:
- First Come First Serve (FCFS)
- Shortest Job First (Non-Preemptive)
- Shortest Job First (Preemptive) / Shortest Remaining Time First (SRTF)
- Round Robin (with configurable time quantum)
-
For each algorithm, the program displays:
- Gantt Chart visualization
- Process completion details in tabular format
- Average Waiting Time
- Average Turnaround Time
To compile the program:
gcc scheduler.c -o schedulerTo run the program:
./scheduler- First, enter the number of processes
- For each process, enter:
- Arrival Time (AT)
- Burst Time (BT)
- Choose the scheduling algorithm from the menu
- For Round Robin, additionally enter the time quantum
For each scheduling algorithm, the program shows:
- Gantt Chart showing the execution sequence
- Table with the following details for each process:
- Process ID
- Arrival Time (AT)
- Burst Time (BT)
- Completion Time (CT)
- Turnaround Time (TAT)
- Waiting Time (WT)
- Average Waiting Time
- Average Turnaround Time
- Arrival Time (AT): Time at which the process enters the ready queue
- Burst Time (BT): Total CPU time required by the process
- Completion Time (CT): Time at which process completes execution
- Turnaround Time (TAT): Total time taken from arrival to completion (CT - AT)
- Waiting Time (WT): Total time spent waiting in ready queue (TAT - BT)
-
First Come First Serve (FCFS)
- Non-preemptive algorithm
- Processes are executed in order of arrival
-
Shortest Job First (Non-Preemptive)
- Non-preemptive algorithm
- Process with shortest burst time is selected for execution
- Process runs to completion once selected
-
Shortest Job First (Preemptive) / SRTF
- Preemptive version of SJF
- Current process can be preempted by a new process with shorter remaining time
- Also known as Shortest Remaining Time First (SRTF)
-
Round Robin
- Preemptive algorithm
- Each process gets CPU for a fixed time quantum
- After time quantum expires, process is moved to end of ready queue
- Provides fair CPU sharing and good response time