Javatpoint Logo
Javatpoint Logo

FCFS Program in Java with Arrival Time

What is FCFS scheduling algorithm?

First Come, First Served (FCFS) is a non-primitive CPU scheduling algorithm. It schedules processes in the order in which they arrive in the ready queue. Processes are executed one by one until completion.

What is arrival time?

Arrival time is the time at which a process arrives in the ready queue.

Non-primitive: Non-primitive scheduling is employed when a process terminates or transitions from running to waiting state.

First in, first out (FIFO), also known as first come, first served (FCFS), is the simplest scheduling algorithm. FIFO simply queues processes in the order that they arrive in the ready queue.

In this, the process that comes first will be executed first and next process starts only after the previous gets fully executed.

Here, we are considering that arrival time for all processes is 0.

  • Completion Time: Time at which process completes its execution.
  • Turn Around Time: Time Difference between completion time and arrival time. Turn Around Time = Completion Time - Arrival Time
  • Waiting Time (W.T): Time Difference between turnaround time and burst time.
  • Waiting Time = Turn Around Time - Burst Time.

Implementation of FCFS

FCFS Algorithm

  • Input the processes along with their burst time (bt).
  • Find waiting time (wt) for all processes.
  • As first process that comes need not to wait so waiting time for process 1 will be 0 i.e. wt[0] = 0.
  • Find waiting time for all other processes i.e. for process i ->wt[i] = bt[i-1] + wt[i-1]
  • Find turnaround time = waiting_time + burst_time for all processes.
  • Find average waiting time = total_waiting_time / no_of_processes.
  • Similarly, find average turnaround time = total_turn_around_time / no_of_processes.

Given n processes with their burst times, the task is to find average waiting time and average turnaround time using FCFS scheduling algorithm.

FCFS.java

Output:

PID     AT      BT      CT      TAT     WT
0       0       10      10      10      0
1       10      5       15      5       0
2       15      8       23      8       0
Avg_turnaround:7.666666666666667
Avg_Waitingtime:0.0

Service Time: Also known as Burst Time, it is the amount of time a process requires to complete its execution on the CPU. It represents the time the CPU spends executing instructions of that particular process.

Waiting Time: It refers to the total amount of time that a process spends waiting in the ready queue before it gets a chance to execute on the CPU.

Implementation of FCFS

  • Input the processes along with their burst time(bt) and arrival time(at)
  • Find waiting time for all other processes i.e. for a given process i: wt[i] = (bt[0] + bt[1] +...... bt[i-1]) - at[i]
  • Now find turnaround time = waiting_time + burst_time for all processes
  • Average waiting time = total_waiting_time / no_of_processes
  • Average turnaround time = total_turn_around_time / no_of_processes

Let's calculate the average waiting time and turnaround time for the following data.

Processes Burst Time Arrival Time Waiting Time Turn-Around Time Completion Time
1 5 0 0 5 5
2 9 3 2 11 14
3 6 6 8 14 20

FCFS.java

Output:

Average waiting time = 3.33333
Average turnaround time = 10.0






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA