fcfs first come first serve scheduling algorithm in java

first come first serve scheduling algorithm

first come first serve scheduling algorithm

first come first serve scheduling algorithm (FCFS) .with this schema the process that request the CPU First is allocated the CPU first.the Implementation of the first come first serve scheduling algorithm (FCFS) policy is easily managed with fifo queue.when a process enters into the ready queue ,its PCB is linked onto the tail of the queue.

when the CPU is free it is allocated to the process at the head of the queue.the running process is then removed from the queue.the code for first come first serve scheduling algorithm (FCFS) is simple to write and Understand.The First come first serve  scheduling algorithm (FCFS) in non preemptive.The first come first serve scheduling algorithm (FCFS) is particularly troublesome for time sharing system.

first come first serve scheduling algorithm Program :


import java.io. * ;
class fcfs {
	public static void main(String args[]) throws Exception {

		int n,
		AT[],
		BT[],
		WT[],
		TAT[];
		float AWT = 0;
		InputStreamReader isr = new InputStreamReader(System. in );
		BufferedReader br = new BufferedReader(isr);
		System.out.println("Enter no of process");
		n = Integer.parseInt(br.readLine());
		BT = new int[n];
		WT = new int[n];
		TAT = new int[n];
		AT = new int[n];
		System.out.println("Enter Burst time for each process\n******************************");
		for (int i = 0; i < n; i++) {
			System.out.println("Enter BT for process " + (i + 1));
			BT[i] = Integer.parseInt(br.readLine());
		}
		System.out.println("***********************************************");
		for (int i = 0; i < n; i++) {
			System.out.println("Enter AT for process" + i);
			AT[i] = Integer.parseInt(br.readLine());
		}
		System.out.println("***********************************************");
		WT[0] = 0;
		for (int i = 1; i < n; i++) {
			WT[i] = WT[i - 1] + BT[i - 1];
			WT[i] = WT[i] - AT[i];
		}
		for (int i = 0; i < n; i++) {
			TAT[i] = WT[i] + BT[i];
			AWT = AWT + WT[i];
		}
		System.out.println(" PROCESS BT WT TAT ");
		for (int i = 0; i < n; i++) {
			System.out.println(" " + i + " " + BT[i] + " " + WT[i] + " " + TAT[i]);
		}
		AWT = AWT / n;
		System.out.println("***********************************************");
		System.out.println("Avg waiting time=" + AWT + "\n***********************************************");

	}
}

/*

Output for first come first serve scheduling algorithm (FCFS) program:

Enter no of process
4
Enter Burst time for each process
******************************
Enter BT for process 1
5
Enter BT for process 2
3
Enter BT for process 3
3
Enter BT for process 4
1
***********************************************
Enter AT for process0
1
Enter AT for process1
2
Enter AT for process2
0
Enter AT for process3
4
***********************************************
PROCESS BT WT TAT
0 5 0 5
1 3 3 6
2 3 6 9
3 1 5 6
***********************************************
Avg waiting time= 3.5
***********************************************
*/

Download “FCFS Program” fcfs.txt – Downloaded 189 times – 1 kB

You may also like...

3 Responses

  1. Rubel miah says:

    FCFS scheduling algorithm describe very easily.

  2. miya says:

    some syntax erroe in this program

Leave a Reply

Your email address will not be published. Required fields are marked *