0% found this document useful (0 votes)
19 views6 pages

22bce7182 FCFS

asdf

Uploaded by

rahul.22bce7182
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views6 pages

22bce7182 FCFS

asdf

Uploaded by

rahul.22bce7182
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

VIT-AP UNIVERSITY, ANDHRA PRADESH

Lab Sheet 2: FCFS Scheduling Algorithm

Branch/ Class: B.Tech Date: 10 Aug 2024

Faculty Name: Prof. Lalitha Kumari Pappala School: SCOPE

Student name: RAHUL KUMAR Reg. no.: 22BCE7182

First-Come, First-Served (FCFS) Scheduling Algorithm Lab Report

1. Introduction

The objective of this experiment is to implement the First-Come, First-Served (FCFS)


scheduling algorithm in Java and to calculate the waiting and turnaround times for a set of
processes.

2. Theory

FCFS Scheduling:

The First-Come, First-Served (FCFS) scheduling algorithm operates on the principle of


executing processes in the order they arrive in the ready queue. The algorithm assigns the
CPU to the process that arrives first, and subsequent processes must wait until the
currently running process finishes. FCFS is easy to implement but can lead to
inefficiencies, particularly when there is a large disparity in process execution times.

Key Metrics:

• Waiting Time: The total time a process spends waiting in the ready queue before it
gets executed. It is calculated as the difference between the turnaround time and
the burst time.
• Turnaround Time: The total time taken from the submission of a process to its
completion. It includes both the waiting time and the burst time of the process.
3. Algorithm

Pseudocode:

1. Initialize waiting time of the first process to 0.


2. For each process from the second to the last:
a. Calculate waiting time as the burst time of the previous process plus the waiting time
of the previous process.
3. For each process:
a. Calculate turnaround time as the burst time of the current process plus its waiting
time.
4. Calculate average waiting time and turnaround time by summing up all individual times
and dividing by the number of processes.
5. Display process details and calculated times.

Explanation of Code:

The code implements the FCFS scheduling algorithm in Java. It calculates the waiting and
turnaround times for a given set of processes and displays the results in a tabular format.
The code is structured into three main methods:

• findWaitingTime: Calculates the waiting time for each process.


• findTurnAroundTime: Calculates the turnaround time for each process.
• findavgTime: Calls the previous methods, calculates average waiting and
turnaround times, and prints the results.

CODE:
import java.text.ParseException;

class RAHUL_22BCE7182 {

// Method to calculate waiting time for all processes

static void findWaitingTime(int[] bt, int[] wt) {


wt[0] = 0; // First process has no waiting time

// Calculate waiting time for each process

for (int i = 1; i < bt.length; i++) {

wt[i] = bt[i - 1] + wt[i - 1];

// Method to calculate turnaround time for all processes

static void findTurnAroundTime(int[] bt, int[] wt, int[] tat) {

for (int i = 0; i < bt.length; i++) {

tat[i] = bt[i] + wt[i];

// Method to calculate and print the average times and process details

static void findavgTime(int[] processes, int[] bt) {

int[] wt = new int[processes.length];

int[] tat = new int[processes.length];

int total_wt = 0, total_tat = 0;

// Calculate waiting and turnaround times

findWaitingTime(bt, wt);

findTurnAroundTime(bt, wt, tat);

// Display process details


System.out.println("Process Burst Time Waiting Time Turnaround Time");

for (int i = 0; i < processes.length; i++) {

total_wt += wt[i];

total_tat += tat[i];

System.out.println(" " + (i + 1) + " " + bt[i] + " " + wt[i] + " " + tat[i]);

// Calculate and display average waiting and turnaround times

float avg_wt = (float) total_wt / processes.length;

float avg_tat = (float) total_tat / processes.length;

System.out.println("\nAverage Waiting Time: " + avg_wt);

System.out.println("Average Turnaround Time: " + avg_tat);

public static void main(String[] args) throws ParseException {

int[] processes = {1, 2, 3}; // Process IDs

int[] burst_time = {10, 5, 8}; // Burst time of each process

// Calculate and display the average times and process details

findavgTime(processes, burst_time);

Output:
(base) rahul_thakur@Rahuls-MacBook-Air c++ % JAVA RAHUL_22BCE7182.java

Process Burst Time Waiting Time Turnaround Time

1 10 0 10
2 5 10 15

3 8 15 23

Average Waiting Time: 8.333333

Average Turnaround Time: 16.0

5. Results

Calculated Values:

To verify the calculations for the processes given, we’ll use the provided data:

Processes:

• Process 1: Burst Time = 10


• Process 2: Burst Time = 5
• Process 3: Burst Time = 8

Waiting Time (WT) and Turnaround Time (TAT) for each process:

1. Process 1:
o Waiting Time (WT1): 0 (since it's the first process)
o Turnaround Time (TAT1): Burst Time + Waiting Time = 10 + 0 = 10
2. Process 2:
o Waiting Time (WT2): Waiting Time of Process 1 = 10 (since Process 2 starts
after Process 1 finishes)
o Turnaround Time (TAT2): Burst Time + Waiting Time = 5 + 10 = 15
3. Process 3:
o Waiting Time (WT3): Waiting Time of Process 2 + Burst Time of Process 2 =
10 + 5 = 15 (since Process 3 starts after Process 2 finishes)
o Turnaround Time (TAT3): Burst Time + Waiting Time = 8 + 15 = 23

Average Waiting Time and Turnaround Time Calculation:

1. Total Waiting Time = WT1 + WT2 + WT3 = 0+10+15 = 25


Average Waiting Time = Total Waiting Time / Number of Process = 25/8 = 8.3333

2. Total Turnaround Time = TAT1 + TAT2 + TAT3 = 10 + 15 + 23 = 48


Average Turnaround Time = Total Turnaround Time / Number of Process
= 48/3 =16

• Average Waiting Time: 8.33 units


• Average Turnaround Time: 16.00 units

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy