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

Monis Os 2

The document outlines an assignment for a CPU Scheduling Lab, specifically focusing on implementing the First Come First Serve (FCFS) scheduling algorithm in C++. It includes a C++ program that calculates the average waiting time and turnaround time for three processes with specified burst times. The final computed average waiting time is 17.0 and the average turnaround time is 27.0.
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)
17 views2 pages

Monis Os 2

The document outlines an assignment for a CPU Scheduling Lab, specifically focusing on implementing the First Come First Serve (FCFS) scheduling algorithm in C++. It includes a C++ program that calculates the average waiting time and turnaround time for three processes with specified burst times. The final computed average waiting time is 17.0 and the average turnaround time is 27.0.
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

Mohd monis choudhary 2023-310-163

Operating Systems Lab: Assignment 2

Learning Objective:

To understand how to code a simple CPU Scheduling Algorithm.

Task:

Write a C++ program to simulate FCFS (First Come First Serve) CPU scheduling algorithm to find average
waiting time for the below problem:

Process Burst Time

P0 24

P1 3

P2 3

Program Input:

Number of Processes and Burst Time for each process.

Program Output:

Average Waiting Time and Turnaround Time.

C++ Code for FCFS Scheduling:

#include <iostream>
using namespace std;
void findWaitingTime(int processes[], int n, int bt[], int wt[]) {
wt[0] = 0;
for (int i = 1; i < n; i++)
wt[i] = bt[i - 1] + wt[i - 1];
}
void findTurnAroundTime(int processes[], int n, int bt[], int wt[], int tat[]) {
for (int i = 0; i < n; i++)
tat[i] = bt[i] + wt[i];
}
void findAverageTime(int processes[], int n, int bt[]) {
int wt[n], tat[n];
float total_wt = 0, total_tat = 0;
findWaitingTime(processes, n, bt, wt);
findTurnAroundTime(processes, n, bt, wt, tat);
cout << "Processes Burst Time Waiting Time Turnaround Time\n";
for (int i = 0; i < n; i++) {
total_wt += wt[i];
total_tat += tat[i];
Mohd monis choudhary 2023-310-163

cout << " " << i << "\t\t" << bt[i] << "\t " << wt[i] << "\t\t " << tat[i] <<
endl;
}
cout << "\nAverage waiting time = " << (total_wt / n);
cout << "\nAverage turnaround time = " << (total_tat / n) << endl;
}
int main() {
int processes[] = {0, 1, 2};
int n = sizeof processes / sizeof processes[0];
int burst_time[] = {24, 3, 3};
findAverageTime(processes, n, burst_time);
return 0;
}

Output:

Final Computed Waiting and Turnaround Times:


Average waiting time = 17.0
Average turnaround time = 27.0

You might also like