25.9k views
4 votes
OS scheduler assignment , please write the code correctly .

-In this assignment, you will implement a simple OS scheduler using C/C++. The scheduler’s task is to receive a set of processes and their details, and then decide the order of executing these processes based on the chosen algorithm. Finally, the scheduler will output the order of process execution, in addition to some stats about each of the processes. The scheduling algorithm chosen for this assignment will be LJF (Longest Job First). This made-up algorithm is the exact opposite of the SJF algorithm you learned in class; It is a non-preemptive algorithm that gives more priority for the longest jobs first. In the assignment, the input will start with an integer N, representing the number of processes, followed by N lines (one for each process). For each line i, the line will start with a string s, representing the process name, followed by 2 numbers representing the arrival time and processing time for the ith process, respectively. These values will be separated by tabs (i.e. ‘\t’). The values for input numbers can be up to 100,000,000. Your program should print a line indicating the order of executing the processes. Moreover, for each process, the program should print a line showing the process’s name, response time, turnaround time, and delay. See the sample output below for details. The input will be read from a file (in.txt), and the output should be written to a file (out.txt). The output format must strictly match the formatting shown in the sample output. Grading Rules: • Each student is expected to fully understand all the aspects and details of the entire code. • Your grade will depend on multiple aspects, such as: 1. The correctness of your code’s output across multiple secret test cases 2. Your code’s ability to handle corner test cases like having many processes or large processing times. 3. Your answers to the questions during the discussion Sample Input (file in.txt): 5 A 0 3 C 4 4 B 2 6 D 6 5 E 8 2 Sample output (file out.txt): A: (response=0, turnaround=3, delay=0) B: (response=1, turnaround=7, delay=1) D: (response=3, turnaround=8, delay=3) C: (response=10, turnaround=14, delay=10) E: (response=10, turnaround=12, delay=10) ABDCE​​​​​​​

User Arjun Kava
by
8.8k points

1 Answer

3 votes

Final answer:

To implement a scheduler using the LJF algorithm in C/C++, you will need to read the input from a file, process the data, and output the order of process execution and statistics for each process.

Step-by-step explanation:

To implement a scheduler using the LJF algorithm in C/C++, you will need to read the input from a file, process the data, and output the order of process execution and statistics for each process. Here's an example of how you can approach this:

  1. First, read the number of processes (N) from the input file.
  2. Then, create a struct or class to represent a process, which should include attributes for the process name, arrival time, processing time, response time, turnaround time, and delay.
  3. Next, create an array or vector to store the processes read from the input file.
  4. Read the N lines from the input file and extract the process details (name, arrival time, and processing time) for each process. Store these details in the array/vector.
  5. Sort the array/vector in descending order of processing time, using any sorting algorithm such as bubble sort or merge sort.
  6. Now, you can iterate over the sorted array/vector and calculate the response time, turnaround time, and delay for each process. For the first process, the response time is 0, and for subsequent processes, the response time is the completion time of the previous process if it arrived earlier. The turnaround time is the sum of response time and processing time, and the delay is the difference between turnaround time and processing time.
  7. Print the order of execution by iterating over the sorted array/vector and printing the process names.
  8. Print the process details (name, response time, turnaround time, and delay) for each process.
  9. Write the output to the output file (out.txt).

This is a basic approach to implementing the LJF scheduler in C/C++. You may need to adapt the code depending on the specific requirements of your assignment. Make sure to handle any edge cases, such as large processing times or a large number of processes, to ensure your code is robust.

User Glen Mazza
by
9.0k points