Project Description

In this project, you will write a program called cpu_scheduler, which simulates Shortest Job First (SJF) and Shortest Remaining Time First (SRTF) CPU scheduling algorithms. The program will be invoked as follows:

./cpu_scheduler < input file> < output file> < algorithm> [limit]

< inputfile> is the name of a text file including the information about the processes to be scheduled and it will have the following format:

< pid> < arrival-time> < burst-time>
  • < pid> is a positive integer number representing the process id of the process
  • < arrival-time> is a non-negative integer number given in milliseconds representing the arrival time of the process
  • < burst-time> is a positive integer number indicating the amount of CPU-time that the process requires

For example, the following can be a sample input file:

1 0 4
2 4 19
3 9 5
4 14 3
5 16 2
6 23 2

Each line of the input file represents a different process, starts without any space, ends with a newline, and there is a single space (' ') in between each field in a line. Note that the example input file provided above is just for illustration purposes. Your program will be tested with much larger input files. Here is more information about the content of the input file:

  • All three fields are guaranteed to appear in the input file.
  • Processes are sorted by their arrival times in increasing order.
  • Processes have unique arrival times.
  • Arrival time of the first process is guaranteed to be 0.

< output file> is the name of the text file including the result of the simulation. You will receive the name as a command line argument, create the file, and fill its content. Each line of the output file will contain the simulation result of a different process previously provided in the input file and the results will have the following format:

< pid> < arrival-time> < finish-time> < waiting-time>

The results in the output file should appear in sorted (increasing) order with respect to their < finish-time>. Each line of the output file should start without any space and should end with a newline, where there is a single space (' ') in between each field in a line. Here is more information about the content of the output file:

  • < finish-time> is a positive integer number in milliseconds representing the completion time of the process with respect to its < arrival-time>
  • < waiting-time> is a non-negative integer number in milliseconds representing the total time the process waited in the ready queue

< algorithm> can be one of the followings:

  • SJF
  • SRTF

SJF will simulate the Shortest Job First CPU scheduling algorithm and SRTF will simulate the Shortest Remaining Time First CPU scheduling algorithm. All units are in milliseconds and all values will be integers. If there is a tie, then use FCFS's rule for that case to break the tie.

[limit] is an optional command-line argument. If this argument is not provided, then you will simulate the whole input file until its end; otherwise, you will only simulate the first [limit] processes. For instance, if limit is given as 10, then you will only simulate the first 10 processes and you program will terminate without simulating the rest of the input file. [limit] is a positive integer less than or equal to the number of lines in the input file.

For example, if your program is invoked as:

./cpu_scheduler in.txt out.txt SJF

then it will read the input file "in.txt", compute the finish time and waiting time of each process provided in this input file by simulating the SJF algorithm, and write the result for each process to "out.txt". Note that input and output file names can be different. Assume that the content of "in.txt" is as the sample input file provided above. Then for this invocation, the content of the output file should be as follows:

1 0 4 0
2 4 23 0
5 16 25 7
6 23 27 2
4 14 30 13
3 9 35 21

For the same input file content, if your program is invoked as:

./cpu_scheduler in.txt out.txt SRTF

then the content of the output file should be as follows:

1 0 4 0
3 9 14 0
4 14 17 0
5 16 19 1
6 23 25 0
2 4 35 12

For the same input file content, if your program is invoked as:

./cpu_scheduler in.txt out.txt SRTF 3

then the content of the output file should be as follows:

1 0 4 0
3 9 14 0
2 4 28 5
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.