Question

Please help me create this CLI CPU Scheduling Simulator in java: First Come First Serve (FCFS)...

Please help me create this CLI CPU Scheduling Simulator in java:

  1. First Come First Serve (FCFS)
  2. Round Robin (RR)

Process information

The process information will be read from an input file. The format is:

pid arrival_time burst_time

All of fields are integer type where:

  • pid is a unique numeric process ID
  • arrival_time is the time when the task arrives in the unit of milliseconds
  • burst_time the is the CPU time requested by a task, in the unit of milliseconds
  • The time unit for arrival_time, burst_time and interval is millisecond.

The program will be run from the command line where you provide the name of the file where the processes are stores.

The simulator first reads task information from input file and stores all data in a data structure. Then it starts simulating one scheduling algorithm in a time-driven manner. At each time unit (or slot), it adds any newly arrived task(s) into the ready queue and calls a specific scheduler algorithm in order to select appropriate task from ready queue. When a task is chosen to run, the simulator prints out a message indicating what process ID is chosen to execute for this time slot. If no task is running (i.e. empty ready queue), it prints out an "idle" message. Before advancing to the next time unit, the simulator should update all necessary changes in task and ready queue status

Inputs and Outputs

Sample input files and expected outputs are shown in the Appendix. You can use it to verify your results. Notice that these input files are not for testing and grading your program in.

  • Your program will output the waiting times of all the processes and compute the average waiting time
  • Your program will output the response times of all the processes and compute the average response time
  • Your program will output the turn-around times of all the processes and compute the average-turn around time

Command-line Usage Examples:

myCPUScheduler input_file [FCFS|RR|MLFQ]

Input file example:

% more input.txt

PID         Arrival   Burst

1              0              10

2              1              9

3              2              8

4              3              7

Output:

When a task is scheduled, the simulator will simply print out what task is selected to run at a time. Show the status of related process at each scheduling event, e.g.,: starts running, has finished, is preempted into Queue #, or continues running.

Print statistical information. As soon as all tasks are completed, the program should compute and print 1) average waiting time, 2) average response time, 3) average turnaround time.

%myCPUScheduler input_file FCFS

Selected Scheduling algorithm: FCFS

PID starts runningat TIME

PID has finished at TIME

PID starts runningat TIME

PID has finished at TIME

=============================

Average waiting time:    10.00 ms

Average response time: 3.00 ms

Average turnaround time: 13.00 ms

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// Java program for implementation of FCFS
// scheduling

import java.io.File;
import java.io.FileNotFoundException;
import java.text.ParseException;
import java.util.Scanner;

public class FCFS {

   // Function to find the waiting time for all
   // processes
      
   static void findWaitingTime(int processes[], int n,
           int bt[], int wt[]) {
       // waiting time for first process is 0
       wt[0] = 0;

       // calculating waiting time
       for (int i = 1; i < n; i++) {
           wt[i] = bt[i - 1] + wt[i - 1];
       }
   }

   // Function to calculate turn around time
   static void findTurnAroundTime(int processes[], int n,
           int bt[], int wt[], int tat[]) {
       // calculating turnaround time by adding
       // bt[i] + wt[i]
       for (int i = 0; i < n; i++) {
           tat[i] = bt[i] + wt[i];
       }
   }

   //Function to calculate average time
   static void findavgTime(int processes[], int n, int bt[]) {
       int wt[] = new int[n], tat[] = new int[n];
       int total_wt = 0, total_tat = 0;

       //Function to find waiting time of all processes
       findWaitingTime(processes, n, bt, wt);

       //Function to find turn around time for all processes
       findTurnAroundTime(processes, n, bt, wt, tat);

       //Display processes along with all details
       System.out.printf("Processes Burst time Waiting"
                   +" time Turn around time\n");

       // Calculate total waiting time and total turn
       // around time
       for (int i = 0; i < n; i++) {
           total_wt = total_wt + wt[i];
           total_tat = total_tat + tat[i];
//            System.out.printf(" %d ", (i + 1));
//            System.out.printf("   %d ", bt[i]);
//            System.out.printf("   %d", wt[i]);
//            System.out.printf("   %d\n", tat[i]);
       }
       float s = (float)total_wt /(float) n;
       int t = total_tat / n;
       System.out.printf("Average waiting time = %f", s);
       System.out.printf("\n");
       System.out.printf("Average turn around time = %d ", t);
   }

   // Driver code
   public static void main(String[] args) throws ParseException, FileNotFoundException {
       String fileName;
       Scanner scanner=new Scanner(System.in);
       fileName=scanner.nextLine();
       File file = new File(fileName);
       int processesid[]=new int[100];
       int arrival[]=new int[100];
       int burst[]=new int[100];
       Scanner sc = new Scanner(file);
       int i=0,j=0;
       while(sc.hasNext())
       {
       String s=sc.nextLine();
           System.out.println(s);
           String str[]=s.split(" ");
           processesid[i]=Integer.parseInt(str[j++]);
           arrival[i]=Integer.parseInt(str[j++]);
           burst[i]=Integer.parseInt(str[j]);
           j=0;
           i++;
       }

       findavgTime(processesid, i--, burst);

   }
}

Add a comment
Know the answer?
Add Answer to:
Please help me create this CLI CPU Scheduling Simulator in java: First Come First Serve (FCFS)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • scheduling program in C, please help 1 Objectives This programming project is to simulate a few...

    scheduling program in C, please help 1 Objectives This programming project is to simulate a few CPU scheduling policies discussed in the class. You will write a C program to implement a simulator with different scheduling algorithms. The simulator selects a task to run from ready queue based on the scheduling algorithm. Since the project intends to simulate a CPU scheduler, so it does not require any actual process creation or execution. When a task is scheduled, the simulator will...

  • Write a program in Java that will simulate FCFS (First Come First Serve) considering context switching...

    Write a program in Java that will simulate FCFS (First Come First Serve) considering context switching is 0. The program should compute waiting time and turnaround time of every job as well as the average waiting time and average turnaround time. Then change the context switching time to 0.4 milliseconds. Arrival time CPU Burst (in milliseconds Process 0) P2 P3 4 100 P6

  • Consider the following set of processes, with the length of the CPU-burst time given in milliseconds:

    Consider the following set of processes, with the length of the CPU-burst time given in milliseconds:Processburst TimePriorityP1103P211P323P414P552For each of the scheduling algorithms, FCFS, Shortest-Job-First (SJF, non-preemptive), Priority (smaller priority number implies higher scheduling priority), and RR (quantum = 1) do the following.Draw a Gantt chart to show how these processes would be scheduled.Give the turnaround time (total time from the first arrival into ready state until CPU-burst is completed) of each process.Give the waiting time (total time spent in the Ready state) of each process.Give...

  • This assignment requires you to create simulations for different scheduling algorithms commonly employed by operating systems...

    This assignment requires you to create simulations for different scheduling algorithms commonly employed by operating systems to achieve multiprogramming. All problems in this assignment assume the following: The simulations you will be creating are for a uniprocessor system (single CPU). Processes in these simulations will require CPU bursts of one or more time units followed by I/O bursts of one or more time units. For simplicity’s sake, when more than one process is executing its I/O burst at the same...

  • Implement the following 3 CPU scheduling algorithms Simulate and evaluate each with the set of eight...

    Implement the following 3 CPU scheduling algorithms Simulate and evaluate each with the set of eight processes below. Use any programming language. The program listing should be submitted with the report. FCFS (First Come First Serve) non-preemptive (partial results provided) SJF non-preemptive MLFQ Multilevel Feedback Queue (absolute priority in higher queues)             Queue 1 uses RR scheduling with Tq = 5             Queue 2 uses RR scheduling with Tq = 10             Queue 3 uses FCFS All processes enter first...

  • operation system please i need the answer now VULTUR Using FCFS (First-Come First-Served) scheduling algorithm, find...

    operation system please i need the answer now VULTUR Using FCFS (First-Come First-Served) scheduling algorithm, find the Average waiting time for the below processes Process Arrival time Service Time P2 P3 P4 TTT Anal 3(12pt) T- Pathp Can there be starvation in first come first serve based scheduling algorithm? Explain. TTT Arial v 3 (12pt) T. 5. 5. Path:p 18 How does Processor scheduling help us in achieving high throughput? Name the three types of Processor scheduling? TT T Arial...

  • Description In this homework, you are asked to implement a multithreaded program that will allow ...

    Description In this homework, you are asked to implement a multithreaded program that will allow us to measure the performance (i.e, CPU utilization, Throughput, Turnaround time, and Waiting time in Ready Queue) of the four basic CPU scheduling algorithms (namely, FIFO, SJE PR, and RR). Your program will be emulating/simulating the processes whose priority, sequence of CPU burst time(ms) and I'O burst time(ms) will be given in an input file. Assume that all scheduling algorithms except RR will be non-preemptive,...

  • Operating System Theory and Design Write a program to simulate the operation of two of CPU...

    Operating System Theory and Design Write a program to simulate the operation of two of CPU scheduling methods. The program does the following: 1. Get the number of processes from the user. 2. Get the burst time of each process from the user 3. Assume that all processes arrive at "O" to the ready queue. 4. The program lets the user select one of the two methods to implement the o e oo implement the CPU scheduling. time. You can...

  • java  Operating System Scheduler Two scheduling strategies for an operating system scheduler are first come first serve...

    java  Operating System Scheduler Two scheduling strategies for an operating system scheduler are first come first serve (FCFS) and fixed priority pre-emptive scheduling (FPPS). Since queues operate on a first come first serve basis, FCFS is implemented using a queue. Similarly, FPPS is implemented using a priority queue. The operating system scheduler simulation is already provided for you. To use it you simply need to modify the main method to run the simulator using either the LinkedListQueue or the PriorityQueue. Run...

  • Please answer the following question in C++ language Consider the following set of processes, with the...

    Please answer the following question in C++ language Consider the following set of processes, with the length of the CPU burst time given in milliseconds: Process            Burst Time      Priority P1. 7 5 P2 2 4 P3 11 3 P4 9 1 P5 5 3 The processes are assumed to have arrived in the order P1,P2, P3, P4, P5, all at time 0. a. Draw four Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: FCFS, SJF, nonpreemptive...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT