0% found this document useful (0 votes)
9 views2 pages

22BPS1110 Os4

The document is a lab assignment on implementing the First Come First Serve (FCFS) CPU scheduling algorithm in C to calculate average waiting time. The code takes user input of process IDs and burst times, calculates individual waiting times by adding previous process burst times, and finds the average waiting time. The output provides performance analysis of FCFS scheduling by measuring average waiting time, with lower times indicating more efficient process execution.

Uploaded by

sahanarameshn
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)
9 views2 pages

22BPS1110 Os4

The document is a lab assignment on implementing the First Come First Serve (FCFS) CPU scheduling algorithm in C to calculate average waiting time. The code takes user input of process IDs and burst times, calculates individual waiting times by adding previous process burst times, and finds the average waiting time. The output provides performance analysis of FCFS scheduling by measuring average waiting time, with lower times indicating more efficient process execution.

Uploaded by

sahanarameshn
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/ 2

LAB ASSIGNMENT- 4

First Come First Serve(FCFS) in Linux


NAME: SAHANA R
REG NO. : 22BPS1110
LAB SLOT: L23+24

Aim: Implementation of FCFS (First come First Serve) algorithm to find average waiting
time .

Source Code:

#include<stdio.h>
void findAverageWaitingTime(int processes[], int n, int bt[]) {
int wt[n];
wt[0] = 0;
for (int i = 1; i < n; i++)
wt[i] = bt[i - 1] + wt[i - 1];
printf("\nIndividual Waiting Times:\n");
for (int i = 0; i < n; i++)
printf("Process %d: %d\n", processes[i], wt[i]);
float avg_wt = 0;
for (int i = 0; i < n; i++)
avg_wt += wt[i];
avg_wt /= n;
printf("\nAverage Waiting Time: %.2f\n", avg_wt);
}
int main() {
int n;
printf("Enter the number of processes: ");
scanf("%d", &n);
int processes[n];
int burst_time[n];
for (int i = 0; i < n; i++) {
printf("Enter burst time for process %d: ", i + 1);
scanf("%d", &burst_time[i]);
processes[i] = i + 1; // Process IDs start from 1
}
findAverageWaitingTime(processes, n, burst_time);
return 0;
}
Output:

The output provides the average waiting time for processes using the FCFS scheduling
algorithm, reflecting the average time processes spend waiting in the ready queue. Lower
average waiting times indicate more efficient process execution. The user input and algorithmic
execution contribute to assessing the scheduling strategy's performance.

Result:

Gantt Charts
Processes Burst Time Waiting time (wt[i] = bt[i - 1]
+ wt[i - 1])

P1 10 0

P2 5 10

P3 8 15
Average Waiting Time: 8.33

Hence we find that the average waiting time of three processes is 8.33 using the FCFS CPU
scheduling.

You might also like