Question

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

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

Dear student,

as per property of FCFS, the process coming first will be executed completely without any interruption or context switching.

The java program is provided below. It simulate FCFS, which sorts processes according to their arrival time and executes and computes waiting & arrival time. It also calculates their average waiting and average arrival time.

import java.util.Scanner;

public class FCFS {

   public static void main(String[] args) {
      
       Scanner sc = new Scanner(System.in);
       int n, i, j, temp, time=0;
       float avg_wt=0, avg_tt=0;
       System.out.println("Enter no. of processes");
       n = sc.nextInt();
      
       int at[] = new int[n+1]; // Arrival time
       int ft[] = new int[n+1]; // Finish time
       int tt[] = new int[n+1]; // Turn around Time
       int wt[] = new int[n+1]; // Waiting time
       int ct[] = new int[n+1]; // CPU/Burst time
       String p[] = new String[n+1]; // Process name
       String ts;
      
       System.out.println("Insert details of processes as (Arrival_time, CPU_time)");
      
       for(i=1;i<=n;i++)
       {
           System.out.println("Process "+i);
           at[i] = sc.nextInt();
           ct[i] = sc.nextInt();
           ft[i] = 0;
           wt[i] = 0;
           tt[i] = 0;
           p[i] = "p"+i;
       }
      
       // sorts processes according to their arrival times
       for(i=1;i<n;i++)
       {
           for(j=0;j<n;j++)
           {
               if(at[j]>at[j+1])
               {
                   temp = at[j];
                   at[j] = at[j+1];
                   at[j+1] = temp;
                  
                   temp = ct[j];
                   ct[j] = ct[j+1];
                   ct[j+1] = temp;  
                  
                   ts = p[j];
                   p[j] = p[j+1];
                   p[j+1] = ts;
               }
           }
       }
      
       // Process each task
       for(i=1;i<=n;i++)
       {
           if(at[i]<=time)
           {
               time += ct[i];
               ft[i] += time;
               tt[i] = ft[i]-at[i];
               wt[i] = tt[i]-ct[i];
               avg_tt += tt[i];
               avg_wt += wt[i];
           }
           else
           {
               while(at[i]>time)
                   time++;
               time += ct[i];
               ft[i] = time;
               tt[i] = ft[i]-at[i];
               wt[i] = tt[i]-ct[i];
               avg_tt += tt[i];
               avg_wt += wt[i];              
           }

       }
      
       avg_tt /= n;
       avg_wt /= n;
       System.out.println("\nProcess AT \tFT \tCT \tTT \tWT");
       for(i=1;i<=n;i++)
       {
           System.out.println(p[i]+"\t"+at[i]+"\t"+ft[i]+"\t"+ct[i]+"\t"+tt[i]+"\t"+wt[i]);
       }
      
       System.out.println("\nAverage turnaound time = "+avg_tt);
       System.out.println("Average waiting time = "+avg_wt);
      
       sc.close();
   }
}

The output of this code for example provided by you is given below.....

Enter no. of processes
6
Insert details of processes as (Arrival_time, CPU_time)
Process 1
0 6
Process 2
3 2
Process 3
5 1
Process 4
9 7
Process 5
10 4
Process 6
11 3

Process AT    FT    CT    TT    WT
p1   0   6   6   6   0
p2   3   8   2   5   3
p3   5   9   1   4   3
p4   9   16   7   7   0
p5   10   20   4   10   6
p6   11   23   3   12   9

Average turnaound time = 7.3333335
Average waiting time = 3.5

Add a comment
Know the answer?
Add Answer to:
Write a program in Java that will simulate FCFS (First Come First Serve) considering context switching...
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
  • Write a Java program that will simulate SRTnext scheduling algorithms. For the algorithm, the pro...

    Write a Java program that will simulate SRTnext scheduling algorithms. For the algorithm, the program should compute waiting time and turnaround time of every job as well as the average waiting time and average turn around time Process Arrival time CPU Burst (in milliseconds) 6 P1 P2 P3 7 10 Ps Write a Java program that will simulate SRTnext scheduling algorithms. For the algorithm, the program should compute waiting time and turnaround time of every job as well as the...

  • 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: First Come First Serve (FCFS) 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...

  • Given the following set of processes with corresponding execution times (in ms), arrival times and priority...

    Given the following set of processes with corresponding execution times (in ms), arrival times and priority (1 – highest).  For each scheduling algorithm: Construct a table showing which process is active and for how long until all processes are completely serviced (as done in class). Calculate the average waiting time and turnaround time. Process ID Burst (ms) Arrival time P1 9 0 P2 12 0 P3 3 0 P4 30 0 P5 20 0 P6 10 0 First Come First Serve...

  • 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...

  • Assume that the three processes arrived in order: Processes                            CPU Burst Time P1  &n

    Assume that the three processes arrived in order: Processes                            CPU Burst Time P1                                           17 P2                                            6 P3                                            8 a.     Please draw the Gantt chart if FCFS scheduling is used. b.    Please calculate the average waiting time and average completion time under FCFS. You MUST show the calculation procedure. c.      Please draw the Gantt chart if Round Robin is used. d.    Please calculate the average waiting time and completion time under RR with q = 3. You MUST show the calculation...

  • 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...

  • 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...

  • QUESTION 1 Consider the following set of processes, with the length of the CPU burst time...

    QUESTION 1 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 priority (a smaller priority number implies a higher priority), and RR (quantum = 2). b. What...

  • 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...

  • Cpu scheduling

    Consider the following set of processes, with the length of the CPU burst times given in milliseconds:a. Draw four Gantt charts illustrating the execution of the processes using FCFS, Preemptive SJF, a non-preemptive priority, and a RR (quantum=2) scheduling. (30 pts)Note: for the RR consider that the arriving time is 0 for all processesb. What is the average waiting time of each process for of the above scheduling algorithms? (10 pts)P1 8 2 0 P2 5 36P3 1 1 8...

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
ADVERTISEMENT