forked from gunanksood/C-Codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFCFS_CPU_scheduling_algorithm.cpp
More file actions
63 lines (52 loc) · 1.51 KB
/
Copy pathFCFS_CPU_scheduling_algorithm.cpp
File metadata and controls
63 lines (52 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* C++ program for implementation of FCFS scheduling algorithm */
/* Given n processes with their Burst times, we find the average waiting time
and average turnaround time using FCFS CPU scheduling Algorithm */
#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 findavgTime(int processes[], int n, int bt[])
{
int wt[n], tat[n], total_wt = 0, total_tat = 0;
findWaitingTime(processes, n, bt, wt);
findTurnAroundTime(processes, n, bt, wt, tat);
cout << "Processes "
<< " Burst time "
<< " Waiting time "
<< " Turn around time\n";
for (int i = 0; i < n; i++)
{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
cout << " " << i + 1 << "\t\t" << bt[i] << "\t "
<< wt[i] << "\t\t " << tat[i] << endl;
}
cout << "Average waiting time = "
<< (float)total_wt / (float)n;
cout << "\nAverage turn around time = "
<< (float)total_tat / (float)n;
}
// Driver code
int main()
{
int processes[] = {1, 2, 3};
int n = sizeof processes / sizeof processes[0];
int burst_time[] = {9, 4, 7};
findavgTime(processes, n, burst_time);
return 0;
}