Write a Program to implement FCFS scheduling algorithm in operating System - KML Tutorial
Aim:-
Write a Program to implement FCFS scheduling algorithm.
Program:-
1. #include<iostream>
2. using namespace std;
3. void findWaitingTime(int processes[], int n,
4. int bt[], int wt[])
5. {
6. wt[0] = 0;
7. for (int i = 1; i < n ; i++ )
8. wt[i] = bt[i-1] + wt[i-1] ;
9. }
10. void findTurnAroundTime( int processes[], int n,
11. int bt[], int wt[], int tat[])
12. {
13. for (int i = 0; i < n ; i++)
14. tat[i] = bt[i] + wt[i];
15. }
16. void findavgTime( int processes[], int n, int bt[])
17. {
18. int wt[n], tat[n], total_wt = 0, total_tat = 0;
19. findWaitingTime(processes, n, bt, wt);
20. findTurnAroundTime(processes, n, bt, wt, tat);
21. cout << "Processes "<< " Burst time "
22. << " Waiting time " << " Turn around time\n";
23. for (int i=0; i<n; i++)
24. {
25. total_wt = total_wt + wt[i];
26. total_tat = total_tat + tat[i];
27. cout << " " << i+1 << "\t\t" << bt[i] <<"\t "
28. << wt[i] <<"\t\t " << tat[i] <<endl;
29. }
30. cout << "Average waiting time = "
31. << (float)total_wt / (float)n;
32. cout << "\nAverage turn around time = "
33. << (float)total_tat / (float)n;
34. }
35. int main()
36. {
37. int processes[] = { 1, 2, 3};
38. int n = sizeof processes / sizeof processes[0];
39. int burst_time[] = {10, 5, 8};
40. findavgTime(processes, n, burst_time);
41. return 0;
42. }
Outpute:-
Processes Burst time Waiting time Turn around time
1 10 0 10
2 5 10 15
3 8 15 23
Average waiting time = 8.33333
Average turn around time = 16
Process returned 0 (0x0) execution time : 0.620 s
****Thank You****
Thank you 🤩 Kamal Daaaa....
ReplyDeleteGood job.
ReplyDelete