added fcfs code
This commit is contained in:
parent
824a7ef5fd
commit
3e3c0978b9
61
Codes/Group B/Assignment - 5/FCFS (Non-Preemptive).cpp
Normal file
61
Codes/Group B/Assignment - 5/FCFS (Non-Preemptive).cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include<iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
struct fcfs{
|
||||||
|
int burst, arrival, id, completion;
|
||||||
|
};
|
||||||
|
fcfs meh[30];
|
||||||
|
|
||||||
|
class FCFS{
|
||||||
|
public:
|
||||||
|
int n;
|
||||||
|
void fcfsIn(){
|
||||||
|
cout<<"\nEnter number of processes: ";
|
||||||
|
cin>>n;
|
||||||
|
for(int i = 0; i < n; i++){
|
||||||
|
cout<<"\nEnter arrival time of P"<<i<<": ";
|
||||||
|
cin>>meh[i].arrival;
|
||||||
|
cout<<"\nEnter burst time of P"<<i<<": ";
|
||||||
|
cin>>meh[i].burst;
|
||||||
|
meh[i].id = i;
|
||||||
|
}
|
||||||
|
cout<<"\n | Arrival | Burst\n";
|
||||||
|
for(int j = 0; j < n; j++) {
|
||||||
|
cout<<"P"<<j<<"| "<<meh[j].arrival<<" | "<<meh[j].burst<<"\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void process() {
|
||||||
|
cout<<"\nSequence of processes is: ";
|
||||||
|
int currentTime = 0;
|
||||||
|
|
||||||
|
for(int i = 0; i < n; i++){
|
||||||
|
if(currentTime < meh[i].arrival){
|
||||||
|
while(currentTime < meh[i].arrival){
|
||||||
|
cout<<" NULL ";
|
||||||
|
currentTime++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout<<"P"<<meh[i].id<<" ";
|
||||||
|
currentTime += meh[i].burst;
|
||||||
|
meh[i].completion = currentTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void completion()
|
||||||
|
{
|
||||||
|
cout<<"\n\n | Completion time\n";
|
||||||
|
for(int j = 0; j < n; j++) {
|
||||||
|
cout<<"P"<<j<<"| "<<meh[j].completion<<"\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
FCFS obj;
|
||||||
|
obj.fcfsIn();
|
||||||
|
obj.process();
|
||||||
|
obj.completion();
|
||||||
|
return 0;
|
||||||
|
}
|
@ -2,4 +2,5 @@
|
|||||||
|
|
||||||
##### Group B
|
##### Group B
|
||||||
5. [CPU Scheduling Algorithms: FCFS, SJF (Preemptive), Priority (Non-Preemptive) and Round Robin (Preemptive)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20B/Assignment%20-%205)
|
5. [CPU Scheduling Algorithms: FCFS, SJF (Preemptive), Priority (Non-Preemptive) and Round Robin (Preemptive)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20B/Assignment%20-%205)
|
||||||
|
- [FCFS (Non-Preemptive)]()
|
||||||
- [SJF (Preemptive)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20B/Assignment%20-%205/SJF%20%28Premptive%29.cpp)
|
- [SJF (Preemptive)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20B/Assignment%20-%205/SJF%20%28Premptive%29.cpp)
|
Loading…
Reference in New Issue
Block a user