0% found this document useful (0 votes)
14 views

First Come First Serve

1. The document describes a First Come First Serve (FCFS) scheduler with 4 processes labeled P1 through P4 with varying burst times and priorities. 2. A Gantt chart shows the processes scheduled in order of arrival time with their start times, finish times, turnaround times, and waiting times calculated. 3. A C++ program is included that calculates the waiting times for each process given their arrival times and burst times, and outputs the average waiting time.

Uploaded by

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

First Come First Serve

1. The document describes a First Come First Serve (FCFS) scheduler with 4 processes labeled P1 through P4 with varying burst times and priorities. 2. A Gantt chart shows the processes scheduled in order of arrival time with their start times, finish times, turnaround times, and waiting times calculated. 3. A C++ program is included that calculates the waiting times for each process given their arrival times and burst times, and outputs the average waiting time.

Uploaded by

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

FIRST COME FIRST SERVE (FCFS) SCHEDULER

PROCESS BURST DURATION (MS) PRIORITY


P1 10 2
P2 8 3
P3 4 4
P4 6 1

GANTT CHART

D A B C
1 7 17 25 29

Turnaround
Job Arrival Time Burst Time Finish Time Waiting Time
Time
D 1 6 7 6 0
A 2 10 17 15 5
B 3 8 25 22 14
C 4 4 29 25 21
Avarage 68 / 4 = 17 40 / 4 = 10

// C++ program to Calculate Waiting


// Time for given Processes
#include <iostream>
using namespace std;
// Function to Calculate waiting time
// and average waiting time
void CalculateWaitingTime(int at[],
int bt[], int N)
{

// Declare the array for waiting


// time
int wt[N];

// Waiting time for first process


// is 0
wt[0] = 0;

// Print waiting time process 1


cout << "PN\t\tAT\t\t"
<< "BT\t\tWT\n\n";
cout << "1"
<< "\t\t" << at[0] << "\t\t"
<< bt[0] << "\t\t" << wt[0] << endl;

// Calculating waiting time for


// each process from the given
// formula
for (int i = 1; i < 4; i++) {
wt[i] = (at[i - 1] + bt[i - 1]
+ wt[i - 1]) - at[i];

// Print the waiting time for


// each process
cout << i + 1 << "\t\t" << at[i]
<< "\t\t" << bt[i] << "\t\t"
<< wt[i] << endl;
}

// Declare variable to calculate


// average
float average;
float sum = 0;

// Loop to calculate sum of all


// waiting time
for (int i = 0; i < 4; i++) {
sum = sum + wt[i];
}

// Find average waiting time


// by dividing it by no. of process
average = sum / 5;

// Print Average Waiting Time


cout << "\nAverage waiting time = "
<< average;
}

// Driver code
int main()
{
// Number of process
int N = 4;

// Array for Arrival time


int at[] = { 2,3,4,1 };

// Array for Burst Time


int bt[] = { 10, 8, 4, 6 };

// Function call to find


// waiting time
CalculateWaitingTime(at, bt, N);
return 0;
}

You might also like