C Implementation:

Write a C program that simulates CPU Scheduling Algorithms. Your program should support only uniprocessor mode and implement the following scheduling algorithms:

  • First Come First Serve (FCFS)
  • Non-preemptive Shortest Job First (SJF)
  • Non-preemptive Priority (0 to 99 priorities inclusive, where 0 means highest priority)
  • Round Robin (RR) with Quantum = 10

As this is a simple CPU scheduling simulator, you're not required to simulate I/O operations, I/O waiting state, interrupts, and/or context switches. However, you should implement your own queue, priority queue, and any other relevant data structure you might need.

Program Input:

Your program will read the information about each process from a file. The first line of the input file should contain a single integer n which represents the number of processes which each of your scheduling algorithms will use. This number will be between 1 and 1000. Following the first line, there will be n lines where each of them will contain 4 integers separated by a single space. The meaning of these integers is as follows:

  • Process ID
  • Process Priority
  • Process Arrival Time (in the Ready Queue)
  • Process CPU Burst Duration

Do note that the lines in the input file will be ordered by the process's arrival time. That said, an example of the input file would be as follows:

10
1 7 75 76
2 73 92 18
3 26 107 42
4 82 115 31
5 89 153 34
6 92 174 48
7 17 246 53
8 90 303 28
9 42 328 61
10 78 372 77

Program Output:

Your program should run all simulators for the provided input. Once all the simulations are complete, your program should output the following report:

  • Name of the scheduler
  • Time in the simulation when the last process finished.
  • Percent of CPU utilization (the amount of time the CPU is running the processes).
  • Throughput in process per second.
  • Average wait time.
  • Average turnaround time.

Program Testing:

To test your program for accuracy use the following C program to generate the relevant program inputs. Do note that to successfully compile this program you need to use the following command: gcc -o gen_scenario gen_scenario.c -std=c99

gen_scenario.c:

#include (stdio.h)
#include (stdlib.h)
#include (time.h)
int gen_random( int min, int max ) {
return min + rand( ) % max;
}
void gen_scenario( int i ) {
int j = 0;
printf( "%dn", i );
for( int j1 = 0; j1 ( i; j1++ ) {
int k = gen_random( 0, 100 );
int l = gen_random( 5, 100 );
int i1 = gen_random( 0, 99 );
printf( "%d %d %d %dn", j1 + 1, i1, j + k, l );
j += k;
}
}
int main( int argc, char* argv[ ] ) {
srand( time( NULL ) );
if( argc ) 1 ) {
gen_scenario( atoi( argv[ 1 ] ) );
} else {
gen_scenario( 10 );
}
return 0;
}

The gen_scenario program will generate process inputs up to the number you’ve specified in the command line argument or up to 10-process inputs otherwise.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.