Follow up: CPU Scheduling Algorithm (SJF, priority & Round Robin)
up vote
3
down vote
favorite
After implementing suggestions from my previous questions about SJF, priority and round robin.
Here I have scheduling.h
which contains a struct Data
and virtual
member functions. Then I have derived class for each scheduling algorithm. Only calcEndTime()
is defined for each scheduling algorithm. I have asked to enter priority in each algortihm because it must be in Data
so it is bounded to arrivalTime
and burstTime
. This is first time I have written program related to inheritance. Suggest me improvements.
scheduling.h
#ifndef SCHEDULING_H_
#define SCHEDULING_H_
#include <vector>
class Scheduler
{
public:
double avgWaitingTime;
double avgTurnAroundTime;
struct Data
{
unsigned arrivalTime;
//When process start to execute
unsigned burstTime;
//only for priority Scheduling
unsigned priority;
Data(unsigned arrivalTime, unsigned burstTime, unsigned priority):
arrivalTime(std::move(arrivalTime)),
burstTime(std::move(burstTime)),
priority(std::move(priority))
{}
Data() = default;
};
std::vector<Data> data;
//process wait to execute after they have arrived
std::vector<unsigned> waitingTime;
//total time taken by processes
std::vector<unsigned> turnAroundTime;
//time when a process end
std::vector<unsigned> endTime;
Scheduler(unsigned num = 0);
Scheduler(const Scheduler&) = delete;
Scheduler &operator=(const Scheduler&) = delete;
Scheduler(Scheduler&&) = delete;
Scheduler &operator=(Scheduler&&) = delete;
~Scheduler() = default;
void calcWaitingTime();
void calcTurnAroundTime();
virtual void calcEndTime() = 0;
void printInfo() const;
};
#endif
scheduling.cpp
#include <iostream>
#include <vector>
#include "scheduling.h"
Scheduler::Scheduler(unsigned num): endTime(num, 0)
{
unsigned arrivalVal, burstVal, priorityVal;
data.reserve(num);
endTime.reserve(num);
waitingTime.reserve(num);
turnAroundTime.reserve(num);
std::cout << "nEnter arrival time and burst time and priority eg(5 18 2)n";
std::cout << "If it is not priority scheduling enter 0 for priorityn";
std::cout << "Lower integer has higher priorityn";
for (unsigned i = 0; i < num; i++)
{
std::cout << "nProcess" << i+1 << ": ";
std::cin >> arrivalVal >> burstVal >> priorityVal;
data.push_back( Data(arrivalVal, burstVal, priorityVal) );
}
}
void Scheduler::calcTurnAroundTime()
{
double sum = 0.00;
for (std::size_t i = 0; i < data.size(); i++)
{
unsigned val = endTime[i] - data[i].arrivalTime;
turnAroundTime.push_back(val);
sum += (double)val;
}
avgTurnAroundTime = sum / turnAroundTime.size();
}
void Scheduler::calcWaitingTime()
{
double sum = 0.00;
for (std::size_t i = 0; i < data.size(); i++)
{
unsigned val = turnAroundTime[i] - data[i].burstTime;
waitingTime.push_back(val);
sum += (double)val;
}
avgWaitingTime = sum / waitingTime.size();
}
void Scheduler::printInfo() const
{
std::cout << "ProcessIDtArrival TimetBurst TimetPrioritytEnd TimetWaiting Time";
std::cout << "tTurnaround Timen";
for (std::size_t i = 0; i < data.size(); i++)
{
std::cout << i+1 << "tt" << data[i].arrivalTime << "tt";
std::cout << data[i].burstTime << "tt" <<data[i].priority << "tt";
std::cout << endTime[i] << "tt";
std::cout << waitingTime[i] <<"tt" << turnAroundTime[i] <<'n';
}
std::cout << "Average Waiting Time : " << avgWaitingTime << 'n';
std::cout << "Average Turn Around Time : " << avgTurnAroundTime << 'n';
}
shortestjobfirst.h
#ifndef SHORTESTJOBFIRST_H_
#define SHORTESTJOBFIRST_H_
#include "scheduling.h"
class ShortestJobFirst : public Scheduler
{
public:
ShortestJobFirst(unsigned num);
ShortestJobFirst() = default;
ShortestJobFirst(const ShortestJobFirst&) = delete;
ShortestJobFirst &operator=(const ShortestJobFirst&) = delete;
ShortestJobFirst(ShortestJobFirst&&) = delete;
ShortestJobFirst &operator=(ShortestJobFirst&&) = delete;
~ShortestJobFirst() = default;
void calcEndTime();
};
#endif
shortestjobfirst.cpp
#include <iostream>
#include <array>
#include <vector>
#include <algorithm> // std::find
#include <iterator> // std::begin, std::end
#include <limits> //std::numeric_limits
#include "scheduling.h"
#include "shortestjobfirst.h"
ShortestJobFirst::ShortestJobFirst(unsigned num) :Scheduler(num)
{}
void ShortestJobFirst::calcEndTime()
{
//If arrival time is not sorted
//sort burst time according to arrival time
static const auto byArrival = (const Data &a, const Data &b)
{
return a.arrivalTime < b.arrivalTime;
};
std::sort(data.begin(), data.end(), byArrival);
//copy values of burst time in new vector
std::vector<unsigned> burstTimeCopy;
for (auto it = data.begin(); it != data.end(); ++it)
{
unsigned val = (*it).burstTime;
burstTimeCopy.push_back(val);
}
unsigned timeCounter = 0;
unsigned currActiveProcessID = 0;
while (!(std::all_of(burstTimeCopy.begin(), burstTimeCopy.end(),
(unsigned e) { return e == 0; })))
{
std::size_t dataSize = data.size();
//All processes are not arrived
if (timeCounter <= data[dataSize -1].arrivalTime)
{
unsigned minBurstTime = std::numeric_limits<uint>::max();
//Find index with minimum burst Time remaining
for (std::size_t i = 0; i < burstTimeCopy.size(); i++)
{
if (burstTimeCopy[i] != 0 && burstTimeCopy[i] < minBurstTime
&& data[i].arrivalTime <= timeCounter)
{
minBurstTime = burstTimeCopy[i];
currActiveProcessID = i;
}
}
burstTimeCopy[currActiveProcessID] -= 1;
timeCounter++;
if (burstTimeCopy[currActiveProcessID] == 0)
{
endTime[currActiveProcessID] = timeCounter;
}
}
else //When all processes are arrived
{
unsigned minBurstTime = std::numeric_limits<uint>::max();
//Find index with minimum burst Time remaining
for (std::size_t i = 0; i < burstTimeCopy.size(); i++)
{
if (burstTimeCopy[i] != 0 && burstTimeCopy[i] < minBurstTime)
{
minBurstTime = burstTimeCopy[i];
currActiveProcessID = i;
}
}
timeCounter += minBurstTime;
endTime[currActiveProcessID] = timeCounter;
burstTimeCopy[currActiveProcessID] = 0;
}
}
}
int main()
{
int num;
std::cout << "Enter the number of processesn";
std::cin >> num;
ShortestJobFirst batch(num);
batch.calcEndTime();
batch.calcTurnAroundTime();
batch.calcWaitingTime();
batch.printInfo();
}
Priority
, ShortestJobFirst
are nearly smae and in RoundRobin
we have member function timeQuantum
which is entered through constructor.
priorit.cpp
#include <iostream>
#include <vector>
#include <algorithm> // std::find
#include <iterator> // std::begin, std::end
#include <limits> //std::numeric_limits
#include "scheduling.h"
#include "priority.h"
Priority::Priority(unsigned num): Scheduler(num)
{}
void Priority::calcEndTime()
{
//If arrival time is not sorted
//sort burst time according to arrival time
static const auto byArrival = (const Data &a, const Data &b)
{
return a.arrivalTime < b.arrivalTime;
};
std::sort(data.begin(), data.end(), byArrival);
//copy values of burst time in new vector
std::vector<unsigned> burstTimeCopy;
for (auto it = data.begin(); it != data.end(); ++it)
{
unsigned val = (*it).burstTime;
burstTimeCopy.push_back(val);
}
unsigned timeCounter = 0;
unsigned currActiveProcessID = 0;
while (!(std::all_of(burstTimeCopy.begin(), burstTimeCopy.end(),
(unsigned e) { return e == 0; })))
{
std::size_t dataSize = data.size();
//All processes are not arrived
if (timeCounter <= data[dataSize - 1].arrivalTime)
{
unsigned maxPriority = std::numeric_limits<uint>::max();
for (std::size_t i = 0; i < burstTimeCopy.size(); i++)
{
if (burstTimeCopy[i] != 0 && data[i].priority < maxPriority
&& data[i].arrivalTime <= timeCounter)
{
maxPriority = data[i].priority;
currActiveProcessID = i;
}
}
burstTimeCopy[currActiveProcessID] -= 1;
timeCounter++;
if (burstTimeCopy[currActiveProcessID] == 0)
{
endTime[currActiveProcessID] = timeCounter;
}
}
else //When all processes are arrived
{
unsigned maxPriority = std::numeric_limits<uint>::max();
for (std::size_t i = 0 ; i < burstTimeCopy.size(); i++)
{
if (burstTimeCopy[i] != 0 && data[i].priority < maxPriority)
{
maxPriority = data[i].priority;
currActiveProcessID = i;
}
}
timeCounter += burstTimeCopy[currActiveProcessID];
burstTimeCopy[currActiveProcessID] = 0;
endTime[currActiveProcessID] = timeCounter;
}
}
}
int main()
{
int num;
std::cout << "Enter the number of processesn";
std::cin >> num;
Priority prioritySchedule(num);
prioritySchedule.calcEndTime();
prioritySchedule.calcTurnAroundTime();
prioritySchedule.calcWaitingTime();
prioritySchedule.printInfo();
}
roundrobin.cpp
#include <iostream>
#include <vector>
#include <algorithm> // std::find
#include <iterator> // std::begin, std::end
#include <limits> //std::numeric_limits
#include "scheduling.h"
#include "roundrobin.h"
RoundRobin::RoundRobin(unsigned num, unsigned quantum): Scheduler(num)
{
timeQuantum = quantum;
}
void RoundRobin::calcEndTime()
{
//If arrival time is not sorted
//sort burst time according to arrival time
static const auto byArrival = (const Data &a, const Data &b)
{
return a.arrivalTime < b.arrivalTime;
};
std::sort(data.begin(), data.end(), byArrival);
//copy values of burst time in new vector
std::vector<unsigned> burstTimeCopy;
for (auto it = data.begin(); it != data.end(); ++it)
{
unsigned val = (*it).burstTime;
burstTimeCopy.push_back(val);
}
unsigned timeCounter = 0;
while (!(std::all_of(burstTimeCopy.begin(), burstTimeCopy.end(),
(unsigned e) { return e == 0; })))
{
unsigned currActiveProcessID = 0;
auto it = burstTimeCopy.begin();
while (it != burstTimeCopy.end())
{
if (burstTimeCopy[currActiveProcessID] > timeQuantum)
{
burstTimeCopy[currActiveProcessID] -= timeQuantum;
timeCounter += timeQuantum;
}
else if (burstTimeCopy[currActiveProcessID] > 0)
{
timeCounter += burstTimeCopy[currActiveProcessID];
burstTimeCopy[currActiveProcessID] = 0;
endTime[currActiveProcessID] = timeCounter;
}
currActiveProcessID++;
it++;
}
}
}
int main()
{
unsigned num, timeQuantum;
std::cout << "Enter number of process: ";
std::cin >> num;
std::cout << "nEnter time quantum : ";
std::cin >> timeQuantum;
RoundRobin roundRobin(num, timeQuantum);
roundRobin.calcEndTime();
roundRobin.calcTurnAroundTime();
roundRobin.calcWaitingTime();
roundRobin.printInfo();
}
c++ c++11
bumped to the homepage by Community♦ 10 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
up vote
3
down vote
favorite
After implementing suggestions from my previous questions about SJF, priority and round robin.
Here I have scheduling.h
which contains a struct Data
and virtual
member functions. Then I have derived class for each scheduling algorithm. Only calcEndTime()
is defined for each scheduling algorithm. I have asked to enter priority in each algortihm because it must be in Data
so it is bounded to arrivalTime
and burstTime
. This is first time I have written program related to inheritance. Suggest me improvements.
scheduling.h
#ifndef SCHEDULING_H_
#define SCHEDULING_H_
#include <vector>
class Scheduler
{
public:
double avgWaitingTime;
double avgTurnAroundTime;
struct Data
{
unsigned arrivalTime;
//When process start to execute
unsigned burstTime;
//only for priority Scheduling
unsigned priority;
Data(unsigned arrivalTime, unsigned burstTime, unsigned priority):
arrivalTime(std::move(arrivalTime)),
burstTime(std::move(burstTime)),
priority(std::move(priority))
{}
Data() = default;
};
std::vector<Data> data;
//process wait to execute after they have arrived
std::vector<unsigned> waitingTime;
//total time taken by processes
std::vector<unsigned> turnAroundTime;
//time when a process end
std::vector<unsigned> endTime;
Scheduler(unsigned num = 0);
Scheduler(const Scheduler&) = delete;
Scheduler &operator=(const Scheduler&) = delete;
Scheduler(Scheduler&&) = delete;
Scheduler &operator=(Scheduler&&) = delete;
~Scheduler() = default;
void calcWaitingTime();
void calcTurnAroundTime();
virtual void calcEndTime() = 0;
void printInfo() const;
};
#endif
scheduling.cpp
#include <iostream>
#include <vector>
#include "scheduling.h"
Scheduler::Scheduler(unsigned num): endTime(num, 0)
{
unsigned arrivalVal, burstVal, priorityVal;
data.reserve(num);
endTime.reserve(num);
waitingTime.reserve(num);
turnAroundTime.reserve(num);
std::cout << "nEnter arrival time and burst time and priority eg(5 18 2)n";
std::cout << "If it is not priority scheduling enter 0 for priorityn";
std::cout << "Lower integer has higher priorityn";
for (unsigned i = 0; i < num; i++)
{
std::cout << "nProcess" << i+1 << ": ";
std::cin >> arrivalVal >> burstVal >> priorityVal;
data.push_back( Data(arrivalVal, burstVal, priorityVal) );
}
}
void Scheduler::calcTurnAroundTime()
{
double sum = 0.00;
for (std::size_t i = 0; i < data.size(); i++)
{
unsigned val = endTime[i] - data[i].arrivalTime;
turnAroundTime.push_back(val);
sum += (double)val;
}
avgTurnAroundTime = sum / turnAroundTime.size();
}
void Scheduler::calcWaitingTime()
{
double sum = 0.00;
for (std::size_t i = 0; i < data.size(); i++)
{
unsigned val = turnAroundTime[i] - data[i].burstTime;
waitingTime.push_back(val);
sum += (double)val;
}
avgWaitingTime = sum / waitingTime.size();
}
void Scheduler::printInfo() const
{
std::cout << "ProcessIDtArrival TimetBurst TimetPrioritytEnd TimetWaiting Time";
std::cout << "tTurnaround Timen";
for (std::size_t i = 0; i < data.size(); i++)
{
std::cout << i+1 << "tt" << data[i].arrivalTime << "tt";
std::cout << data[i].burstTime << "tt" <<data[i].priority << "tt";
std::cout << endTime[i] << "tt";
std::cout << waitingTime[i] <<"tt" << turnAroundTime[i] <<'n';
}
std::cout << "Average Waiting Time : " << avgWaitingTime << 'n';
std::cout << "Average Turn Around Time : " << avgTurnAroundTime << 'n';
}
shortestjobfirst.h
#ifndef SHORTESTJOBFIRST_H_
#define SHORTESTJOBFIRST_H_
#include "scheduling.h"
class ShortestJobFirst : public Scheduler
{
public:
ShortestJobFirst(unsigned num);
ShortestJobFirst() = default;
ShortestJobFirst(const ShortestJobFirst&) = delete;
ShortestJobFirst &operator=(const ShortestJobFirst&) = delete;
ShortestJobFirst(ShortestJobFirst&&) = delete;
ShortestJobFirst &operator=(ShortestJobFirst&&) = delete;
~ShortestJobFirst() = default;
void calcEndTime();
};
#endif
shortestjobfirst.cpp
#include <iostream>
#include <array>
#include <vector>
#include <algorithm> // std::find
#include <iterator> // std::begin, std::end
#include <limits> //std::numeric_limits
#include "scheduling.h"
#include "shortestjobfirst.h"
ShortestJobFirst::ShortestJobFirst(unsigned num) :Scheduler(num)
{}
void ShortestJobFirst::calcEndTime()
{
//If arrival time is not sorted
//sort burst time according to arrival time
static const auto byArrival = (const Data &a, const Data &b)
{
return a.arrivalTime < b.arrivalTime;
};
std::sort(data.begin(), data.end(), byArrival);
//copy values of burst time in new vector
std::vector<unsigned> burstTimeCopy;
for (auto it = data.begin(); it != data.end(); ++it)
{
unsigned val = (*it).burstTime;
burstTimeCopy.push_back(val);
}
unsigned timeCounter = 0;
unsigned currActiveProcessID = 0;
while (!(std::all_of(burstTimeCopy.begin(), burstTimeCopy.end(),
(unsigned e) { return e == 0; })))
{
std::size_t dataSize = data.size();
//All processes are not arrived
if (timeCounter <= data[dataSize -1].arrivalTime)
{
unsigned minBurstTime = std::numeric_limits<uint>::max();
//Find index with minimum burst Time remaining
for (std::size_t i = 0; i < burstTimeCopy.size(); i++)
{
if (burstTimeCopy[i] != 0 && burstTimeCopy[i] < minBurstTime
&& data[i].arrivalTime <= timeCounter)
{
minBurstTime = burstTimeCopy[i];
currActiveProcessID = i;
}
}
burstTimeCopy[currActiveProcessID] -= 1;
timeCounter++;
if (burstTimeCopy[currActiveProcessID] == 0)
{
endTime[currActiveProcessID] = timeCounter;
}
}
else //When all processes are arrived
{
unsigned minBurstTime = std::numeric_limits<uint>::max();
//Find index with minimum burst Time remaining
for (std::size_t i = 0; i < burstTimeCopy.size(); i++)
{
if (burstTimeCopy[i] != 0 && burstTimeCopy[i] < minBurstTime)
{
minBurstTime = burstTimeCopy[i];
currActiveProcessID = i;
}
}
timeCounter += minBurstTime;
endTime[currActiveProcessID] = timeCounter;
burstTimeCopy[currActiveProcessID] = 0;
}
}
}
int main()
{
int num;
std::cout << "Enter the number of processesn";
std::cin >> num;
ShortestJobFirst batch(num);
batch.calcEndTime();
batch.calcTurnAroundTime();
batch.calcWaitingTime();
batch.printInfo();
}
Priority
, ShortestJobFirst
are nearly smae and in RoundRobin
we have member function timeQuantum
which is entered through constructor.
priorit.cpp
#include <iostream>
#include <vector>
#include <algorithm> // std::find
#include <iterator> // std::begin, std::end
#include <limits> //std::numeric_limits
#include "scheduling.h"
#include "priority.h"
Priority::Priority(unsigned num): Scheduler(num)
{}
void Priority::calcEndTime()
{
//If arrival time is not sorted
//sort burst time according to arrival time
static const auto byArrival = (const Data &a, const Data &b)
{
return a.arrivalTime < b.arrivalTime;
};
std::sort(data.begin(), data.end(), byArrival);
//copy values of burst time in new vector
std::vector<unsigned> burstTimeCopy;
for (auto it = data.begin(); it != data.end(); ++it)
{
unsigned val = (*it).burstTime;
burstTimeCopy.push_back(val);
}
unsigned timeCounter = 0;
unsigned currActiveProcessID = 0;
while (!(std::all_of(burstTimeCopy.begin(), burstTimeCopy.end(),
(unsigned e) { return e == 0; })))
{
std::size_t dataSize = data.size();
//All processes are not arrived
if (timeCounter <= data[dataSize - 1].arrivalTime)
{
unsigned maxPriority = std::numeric_limits<uint>::max();
for (std::size_t i = 0; i < burstTimeCopy.size(); i++)
{
if (burstTimeCopy[i] != 0 && data[i].priority < maxPriority
&& data[i].arrivalTime <= timeCounter)
{
maxPriority = data[i].priority;
currActiveProcessID = i;
}
}
burstTimeCopy[currActiveProcessID] -= 1;
timeCounter++;
if (burstTimeCopy[currActiveProcessID] == 0)
{
endTime[currActiveProcessID] = timeCounter;
}
}
else //When all processes are arrived
{
unsigned maxPriority = std::numeric_limits<uint>::max();
for (std::size_t i = 0 ; i < burstTimeCopy.size(); i++)
{
if (burstTimeCopy[i] != 0 && data[i].priority < maxPriority)
{
maxPriority = data[i].priority;
currActiveProcessID = i;
}
}
timeCounter += burstTimeCopy[currActiveProcessID];
burstTimeCopy[currActiveProcessID] = 0;
endTime[currActiveProcessID] = timeCounter;
}
}
}
int main()
{
int num;
std::cout << "Enter the number of processesn";
std::cin >> num;
Priority prioritySchedule(num);
prioritySchedule.calcEndTime();
prioritySchedule.calcTurnAroundTime();
prioritySchedule.calcWaitingTime();
prioritySchedule.printInfo();
}
roundrobin.cpp
#include <iostream>
#include <vector>
#include <algorithm> // std::find
#include <iterator> // std::begin, std::end
#include <limits> //std::numeric_limits
#include "scheduling.h"
#include "roundrobin.h"
RoundRobin::RoundRobin(unsigned num, unsigned quantum): Scheduler(num)
{
timeQuantum = quantum;
}
void RoundRobin::calcEndTime()
{
//If arrival time is not sorted
//sort burst time according to arrival time
static const auto byArrival = (const Data &a, const Data &b)
{
return a.arrivalTime < b.arrivalTime;
};
std::sort(data.begin(), data.end(), byArrival);
//copy values of burst time in new vector
std::vector<unsigned> burstTimeCopy;
for (auto it = data.begin(); it != data.end(); ++it)
{
unsigned val = (*it).burstTime;
burstTimeCopy.push_back(val);
}
unsigned timeCounter = 0;
while (!(std::all_of(burstTimeCopy.begin(), burstTimeCopy.end(),
(unsigned e) { return e == 0; })))
{
unsigned currActiveProcessID = 0;
auto it = burstTimeCopy.begin();
while (it != burstTimeCopy.end())
{
if (burstTimeCopy[currActiveProcessID] > timeQuantum)
{
burstTimeCopy[currActiveProcessID] -= timeQuantum;
timeCounter += timeQuantum;
}
else if (burstTimeCopy[currActiveProcessID] > 0)
{
timeCounter += burstTimeCopy[currActiveProcessID];
burstTimeCopy[currActiveProcessID] = 0;
endTime[currActiveProcessID] = timeCounter;
}
currActiveProcessID++;
it++;
}
}
}
int main()
{
unsigned num, timeQuantum;
std::cout << "Enter number of process: ";
std::cin >> num;
std::cout << "nEnter time quantum : ";
std::cin >> timeQuantum;
RoundRobin roundRobin(num, timeQuantum);
roundRobin.calcEndTime();
roundRobin.calcTurnAroundTime();
roundRobin.calcWaitingTime();
roundRobin.printInfo();
}
c++ c++11
bumped to the homepage by Community♦ 10 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
After implementing suggestions from my previous questions about SJF, priority and round robin.
Here I have scheduling.h
which contains a struct Data
and virtual
member functions. Then I have derived class for each scheduling algorithm. Only calcEndTime()
is defined for each scheduling algorithm. I have asked to enter priority in each algortihm because it must be in Data
so it is bounded to arrivalTime
and burstTime
. This is first time I have written program related to inheritance. Suggest me improvements.
scheduling.h
#ifndef SCHEDULING_H_
#define SCHEDULING_H_
#include <vector>
class Scheduler
{
public:
double avgWaitingTime;
double avgTurnAroundTime;
struct Data
{
unsigned arrivalTime;
//When process start to execute
unsigned burstTime;
//only for priority Scheduling
unsigned priority;
Data(unsigned arrivalTime, unsigned burstTime, unsigned priority):
arrivalTime(std::move(arrivalTime)),
burstTime(std::move(burstTime)),
priority(std::move(priority))
{}
Data() = default;
};
std::vector<Data> data;
//process wait to execute after they have arrived
std::vector<unsigned> waitingTime;
//total time taken by processes
std::vector<unsigned> turnAroundTime;
//time when a process end
std::vector<unsigned> endTime;
Scheduler(unsigned num = 0);
Scheduler(const Scheduler&) = delete;
Scheduler &operator=(const Scheduler&) = delete;
Scheduler(Scheduler&&) = delete;
Scheduler &operator=(Scheduler&&) = delete;
~Scheduler() = default;
void calcWaitingTime();
void calcTurnAroundTime();
virtual void calcEndTime() = 0;
void printInfo() const;
};
#endif
scheduling.cpp
#include <iostream>
#include <vector>
#include "scheduling.h"
Scheduler::Scheduler(unsigned num): endTime(num, 0)
{
unsigned arrivalVal, burstVal, priorityVal;
data.reserve(num);
endTime.reserve(num);
waitingTime.reserve(num);
turnAroundTime.reserve(num);
std::cout << "nEnter arrival time and burst time and priority eg(5 18 2)n";
std::cout << "If it is not priority scheduling enter 0 for priorityn";
std::cout << "Lower integer has higher priorityn";
for (unsigned i = 0; i < num; i++)
{
std::cout << "nProcess" << i+1 << ": ";
std::cin >> arrivalVal >> burstVal >> priorityVal;
data.push_back( Data(arrivalVal, burstVal, priorityVal) );
}
}
void Scheduler::calcTurnAroundTime()
{
double sum = 0.00;
for (std::size_t i = 0; i < data.size(); i++)
{
unsigned val = endTime[i] - data[i].arrivalTime;
turnAroundTime.push_back(val);
sum += (double)val;
}
avgTurnAroundTime = sum / turnAroundTime.size();
}
void Scheduler::calcWaitingTime()
{
double sum = 0.00;
for (std::size_t i = 0; i < data.size(); i++)
{
unsigned val = turnAroundTime[i] - data[i].burstTime;
waitingTime.push_back(val);
sum += (double)val;
}
avgWaitingTime = sum / waitingTime.size();
}
void Scheduler::printInfo() const
{
std::cout << "ProcessIDtArrival TimetBurst TimetPrioritytEnd TimetWaiting Time";
std::cout << "tTurnaround Timen";
for (std::size_t i = 0; i < data.size(); i++)
{
std::cout << i+1 << "tt" << data[i].arrivalTime << "tt";
std::cout << data[i].burstTime << "tt" <<data[i].priority << "tt";
std::cout << endTime[i] << "tt";
std::cout << waitingTime[i] <<"tt" << turnAroundTime[i] <<'n';
}
std::cout << "Average Waiting Time : " << avgWaitingTime << 'n';
std::cout << "Average Turn Around Time : " << avgTurnAroundTime << 'n';
}
shortestjobfirst.h
#ifndef SHORTESTJOBFIRST_H_
#define SHORTESTJOBFIRST_H_
#include "scheduling.h"
class ShortestJobFirst : public Scheduler
{
public:
ShortestJobFirst(unsigned num);
ShortestJobFirst() = default;
ShortestJobFirst(const ShortestJobFirst&) = delete;
ShortestJobFirst &operator=(const ShortestJobFirst&) = delete;
ShortestJobFirst(ShortestJobFirst&&) = delete;
ShortestJobFirst &operator=(ShortestJobFirst&&) = delete;
~ShortestJobFirst() = default;
void calcEndTime();
};
#endif
shortestjobfirst.cpp
#include <iostream>
#include <array>
#include <vector>
#include <algorithm> // std::find
#include <iterator> // std::begin, std::end
#include <limits> //std::numeric_limits
#include "scheduling.h"
#include "shortestjobfirst.h"
ShortestJobFirst::ShortestJobFirst(unsigned num) :Scheduler(num)
{}
void ShortestJobFirst::calcEndTime()
{
//If arrival time is not sorted
//sort burst time according to arrival time
static const auto byArrival = (const Data &a, const Data &b)
{
return a.arrivalTime < b.arrivalTime;
};
std::sort(data.begin(), data.end(), byArrival);
//copy values of burst time in new vector
std::vector<unsigned> burstTimeCopy;
for (auto it = data.begin(); it != data.end(); ++it)
{
unsigned val = (*it).burstTime;
burstTimeCopy.push_back(val);
}
unsigned timeCounter = 0;
unsigned currActiveProcessID = 0;
while (!(std::all_of(burstTimeCopy.begin(), burstTimeCopy.end(),
(unsigned e) { return e == 0; })))
{
std::size_t dataSize = data.size();
//All processes are not arrived
if (timeCounter <= data[dataSize -1].arrivalTime)
{
unsigned minBurstTime = std::numeric_limits<uint>::max();
//Find index with minimum burst Time remaining
for (std::size_t i = 0; i < burstTimeCopy.size(); i++)
{
if (burstTimeCopy[i] != 0 && burstTimeCopy[i] < minBurstTime
&& data[i].arrivalTime <= timeCounter)
{
minBurstTime = burstTimeCopy[i];
currActiveProcessID = i;
}
}
burstTimeCopy[currActiveProcessID] -= 1;
timeCounter++;
if (burstTimeCopy[currActiveProcessID] == 0)
{
endTime[currActiveProcessID] = timeCounter;
}
}
else //When all processes are arrived
{
unsigned minBurstTime = std::numeric_limits<uint>::max();
//Find index with minimum burst Time remaining
for (std::size_t i = 0; i < burstTimeCopy.size(); i++)
{
if (burstTimeCopy[i] != 0 && burstTimeCopy[i] < minBurstTime)
{
minBurstTime = burstTimeCopy[i];
currActiveProcessID = i;
}
}
timeCounter += minBurstTime;
endTime[currActiveProcessID] = timeCounter;
burstTimeCopy[currActiveProcessID] = 0;
}
}
}
int main()
{
int num;
std::cout << "Enter the number of processesn";
std::cin >> num;
ShortestJobFirst batch(num);
batch.calcEndTime();
batch.calcTurnAroundTime();
batch.calcWaitingTime();
batch.printInfo();
}
Priority
, ShortestJobFirst
are nearly smae and in RoundRobin
we have member function timeQuantum
which is entered through constructor.
priorit.cpp
#include <iostream>
#include <vector>
#include <algorithm> // std::find
#include <iterator> // std::begin, std::end
#include <limits> //std::numeric_limits
#include "scheduling.h"
#include "priority.h"
Priority::Priority(unsigned num): Scheduler(num)
{}
void Priority::calcEndTime()
{
//If arrival time is not sorted
//sort burst time according to arrival time
static const auto byArrival = (const Data &a, const Data &b)
{
return a.arrivalTime < b.arrivalTime;
};
std::sort(data.begin(), data.end(), byArrival);
//copy values of burst time in new vector
std::vector<unsigned> burstTimeCopy;
for (auto it = data.begin(); it != data.end(); ++it)
{
unsigned val = (*it).burstTime;
burstTimeCopy.push_back(val);
}
unsigned timeCounter = 0;
unsigned currActiveProcessID = 0;
while (!(std::all_of(burstTimeCopy.begin(), burstTimeCopy.end(),
(unsigned e) { return e == 0; })))
{
std::size_t dataSize = data.size();
//All processes are not arrived
if (timeCounter <= data[dataSize - 1].arrivalTime)
{
unsigned maxPriority = std::numeric_limits<uint>::max();
for (std::size_t i = 0; i < burstTimeCopy.size(); i++)
{
if (burstTimeCopy[i] != 0 && data[i].priority < maxPriority
&& data[i].arrivalTime <= timeCounter)
{
maxPriority = data[i].priority;
currActiveProcessID = i;
}
}
burstTimeCopy[currActiveProcessID] -= 1;
timeCounter++;
if (burstTimeCopy[currActiveProcessID] == 0)
{
endTime[currActiveProcessID] = timeCounter;
}
}
else //When all processes are arrived
{
unsigned maxPriority = std::numeric_limits<uint>::max();
for (std::size_t i = 0 ; i < burstTimeCopy.size(); i++)
{
if (burstTimeCopy[i] != 0 && data[i].priority < maxPriority)
{
maxPriority = data[i].priority;
currActiveProcessID = i;
}
}
timeCounter += burstTimeCopy[currActiveProcessID];
burstTimeCopy[currActiveProcessID] = 0;
endTime[currActiveProcessID] = timeCounter;
}
}
}
int main()
{
int num;
std::cout << "Enter the number of processesn";
std::cin >> num;
Priority prioritySchedule(num);
prioritySchedule.calcEndTime();
prioritySchedule.calcTurnAroundTime();
prioritySchedule.calcWaitingTime();
prioritySchedule.printInfo();
}
roundrobin.cpp
#include <iostream>
#include <vector>
#include <algorithm> // std::find
#include <iterator> // std::begin, std::end
#include <limits> //std::numeric_limits
#include "scheduling.h"
#include "roundrobin.h"
RoundRobin::RoundRobin(unsigned num, unsigned quantum): Scheduler(num)
{
timeQuantum = quantum;
}
void RoundRobin::calcEndTime()
{
//If arrival time is not sorted
//sort burst time according to arrival time
static const auto byArrival = (const Data &a, const Data &b)
{
return a.arrivalTime < b.arrivalTime;
};
std::sort(data.begin(), data.end(), byArrival);
//copy values of burst time in new vector
std::vector<unsigned> burstTimeCopy;
for (auto it = data.begin(); it != data.end(); ++it)
{
unsigned val = (*it).burstTime;
burstTimeCopy.push_back(val);
}
unsigned timeCounter = 0;
while (!(std::all_of(burstTimeCopy.begin(), burstTimeCopy.end(),
(unsigned e) { return e == 0; })))
{
unsigned currActiveProcessID = 0;
auto it = burstTimeCopy.begin();
while (it != burstTimeCopy.end())
{
if (burstTimeCopy[currActiveProcessID] > timeQuantum)
{
burstTimeCopy[currActiveProcessID] -= timeQuantum;
timeCounter += timeQuantum;
}
else if (burstTimeCopy[currActiveProcessID] > 0)
{
timeCounter += burstTimeCopy[currActiveProcessID];
burstTimeCopy[currActiveProcessID] = 0;
endTime[currActiveProcessID] = timeCounter;
}
currActiveProcessID++;
it++;
}
}
}
int main()
{
unsigned num, timeQuantum;
std::cout << "Enter number of process: ";
std::cin >> num;
std::cout << "nEnter time quantum : ";
std::cin >> timeQuantum;
RoundRobin roundRobin(num, timeQuantum);
roundRobin.calcEndTime();
roundRobin.calcTurnAroundTime();
roundRobin.calcWaitingTime();
roundRobin.printInfo();
}
c++ c++11
After implementing suggestions from my previous questions about SJF, priority and round robin.
Here I have scheduling.h
which contains a struct Data
and virtual
member functions. Then I have derived class for each scheduling algorithm. Only calcEndTime()
is defined for each scheduling algorithm. I have asked to enter priority in each algortihm because it must be in Data
so it is bounded to arrivalTime
and burstTime
. This is first time I have written program related to inheritance. Suggest me improvements.
scheduling.h
#ifndef SCHEDULING_H_
#define SCHEDULING_H_
#include <vector>
class Scheduler
{
public:
double avgWaitingTime;
double avgTurnAroundTime;
struct Data
{
unsigned arrivalTime;
//When process start to execute
unsigned burstTime;
//only for priority Scheduling
unsigned priority;
Data(unsigned arrivalTime, unsigned burstTime, unsigned priority):
arrivalTime(std::move(arrivalTime)),
burstTime(std::move(burstTime)),
priority(std::move(priority))
{}
Data() = default;
};
std::vector<Data> data;
//process wait to execute after they have arrived
std::vector<unsigned> waitingTime;
//total time taken by processes
std::vector<unsigned> turnAroundTime;
//time when a process end
std::vector<unsigned> endTime;
Scheduler(unsigned num = 0);
Scheduler(const Scheduler&) = delete;
Scheduler &operator=(const Scheduler&) = delete;
Scheduler(Scheduler&&) = delete;
Scheduler &operator=(Scheduler&&) = delete;
~Scheduler() = default;
void calcWaitingTime();
void calcTurnAroundTime();
virtual void calcEndTime() = 0;
void printInfo() const;
};
#endif
scheduling.cpp
#include <iostream>
#include <vector>
#include "scheduling.h"
Scheduler::Scheduler(unsigned num): endTime(num, 0)
{
unsigned arrivalVal, burstVal, priorityVal;
data.reserve(num);
endTime.reserve(num);
waitingTime.reserve(num);
turnAroundTime.reserve(num);
std::cout << "nEnter arrival time and burst time and priority eg(5 18 2)n";
std::cout << "If it is not priority scheduling enter 0 for priorityn";
std::cout << "Lower integer has higher priorityn";
for (unsigned i = 0; i < num; i++)
{
std::cout << "nProcess" << i+1 << ": ";
std::cin >> arrivalVal >> burstVal >> priorityVal;
data.push_back( Data(arrivalVal, burstVal, priorityVal) );
}
}
void Scheduler::calcTurnAroundTime()
{
double sum = 0.00;
for (std::size_t i = 0; i < data.size(); i++)
{
unsigned val = endTime[i] - data[i].arrivalTime;
turnAroundTime.push_back(val);
sum += (double)val;
}
avgTurnAroundTime = sum / turnAroundTime.size();
}
void Scheduler::calcWaitingTime()
{
double sum = 0.00;
for (std::size_t i = 0; i < data.size(); i++)
{
unsigned val = turnAroundTime[i] - data[i].burstTime;
waitingTime.push_back(val);
sum += (double)val;
}
avgWaitingTime = sum / waitingTime.size();
}
void Scheduler::printInfo() const
{
std::cout << "ProcessIDtArrival TimetBurst TimetPrioritytEnd TimetWaiting Time";
std::cout << "tTurnaround Timen";
for (std::size_t i = 0; i < data.size(); i++)
{
std::cout << i+1 << "tt" << data[i].arrivalTime << "tt";
std::cout << data[i].burstTime << "tt" <<data[i].priority << "tt";
std::cout << endTime[i] << "tt";
std::cout << waitingTime[i] <<"tt" << turnAroundTime[i] <<'n';
}
std::cout << "Average Waiting Time : " << avgWaitingTime << 'n';
std::cout << "Average Turn Around Time : " << avgTurnAroundTime << 'n';
}
shortestjobfirst.h
#ifndef SHORTESTJOBFIRST_H_
#define SHORTESTJOBFIRST_H_
#include "scheduling.h"
class ShortestJobFirst : public Scheduler
{
public:
ShortestJobFirst(unsigned num);
ShortestJobFirst() = default;
ShortestJobFirst(const ShortestJobFirst&) = delete;
ShortestJobFirst &operator=(const ShortestJobFirst&) = delete;
ShortestJobFirst(ShortestJobFirst&&) = delete;
ShortestJobFirst &operator=(ShortestJobFirst&&) = delete;
~ShortestJobFirst() = default;
void calcEndTime();
};
#endif
shortestjobfirst.cpp
#include <iostream>
#include <array>
#include <vector>
#include <algorithm> // std::find
#include <iterator> // std::begin, std::end
#include <limits> //std::numeric_limits
#include "scheduling.h"
#include "shortestjobfirst.h"
ShortestJobFirst::ShortestJobFirst(unsigned num) :Scheduler(num)
{}
void ShortestJobFirst::calcEndTime()
{
//If arrival time is not sorted
//sort burst time according to arrival time
static const auto byArrival = (const Data &a, const Data &b)
{
return a.arrivalTime < b.arrivalTime;
};
std::sort(data.begin(), data.end(), byArrival);
//copy values of burst time in new vector
std::vector<unsigned> burstTimeCopy;
for (auto it = data.begin(); it != data.end(); ++it)
{
unsigned val = (*it).burstTime;
burstTimeCopy.push_back(val);
}
unsigned timeCounter = 0;
unsigned currActiveProcessID = 0;
while (!(std::all_of(burstTimeCopy.begin(), burstTimeCopy.end(),
(unsigned e) { return e == 0; })))
{
std::size_t dataSize = data.size();
//All processes are not arrived
if (timeCounter <= data[dataSize -1].arrivalTime)
{
unsigned minBurstTime = std::numeric_limits<uint>::max();
//Find index with minimum burst Time remaining
for (std::size_t i = 0; i < burstTimeCopy.size(); i++)
{
if (burstTimeCopy[i] != 0 && burstTimeCopy[i] < minBurstTime
&& data[i].arrivalTime <= timeCounter)
{
minBurstTime = burstTimeCopy[i];
currActiveProcessID = i;
}
}
burstTimeCopy[currActiveProcessID] -= 1;
timeCounter++;
if (burstTimeCopy[currActiveProcessID] == 0)
{
endTime[currActiveProcessID] = timeCounter;
}
}
else //When all processes are arrived
{
unsigned minBurstTime = std::numeric_limits<uint>::max();
//Find index with minimum burst Time remaining
for (std::size_t i = 0; i < burstTimeCopy.size(); i++)
{
if (burstTimeCopy[i] != 0 && burstTimeCopy[i] < minBurstTime)
{
minBurstTime = burstTimeCopy[i];
currActiveProcessID = i;
}
}
timeCounter += minBurstTime;
endTime[currActiveProcessID] = timeCounter;
burstTimeCopy[currActiveProcessID] = 0;
}
}
}
int main()
{
int num;
std::cout << "Enter the number of processesn";
std::cin >> num;
ShortestJobFirst batch(num);
batch.calcEndTime();
batch.calcTurnAroundTime();
batch.calcWaitingTime();
batch.printInfo();
}
Priority
, ShortestJobFirst
are nearly smae and in RoundRobin
we have member function timeQuantum
which is entered through constructor.
priorit.cpp
#include <iostream>
#include <vector>
#include <algorithm> // std::find
#include <iterator> // std::begin, std::end
#include <limits> //std::numeric_limits
#include "scheduling.h"
#include "priority.h"
Priority::Priority(unsigned num): Scheduler(num)
{}
void Priority::calcEndTime()
{
//If arrival time is not sorted
//sort burst time according to arrival time
static const auto byArrival = (const Data &a, const Data &b)
{
return a.arrivalTime < b.arrivalTime;
};
std::sort(data.begin(), data.end(), byArrival);
//copy values of burst time in new vector
std::vector<unsigned> burstTimeCopy;
for (auto it = data.begin(); it != data.end(); ++it)
{
unsigned val = (*it).burstTime;
burstTimeCopy.push_back(val);
}
unsigned timeCounter = 0;
unsigned currActiveProcessID = 0;
while (!(std::all_of(burstTimeCopy.begin(), burstTimeCopy.end(),
(unsigned e) { return e == 0; })))
{
std::size_t dataSize = data.size();
//All processes are not arrived
if (timeCounter <= data[dataSize - 1].arrivalTime)
{
unsigned maxPriority = std::numeric_limits<uint>::max();
for (std::size_t i = 0; i < burstTimeCopy.size(); i++)
{
if (burstTimeCopy[i] != 0 && data[i].priority < maxPriority
&& data[i].arrivalTime <= timeCounter)
{
maxPriority = data[i].priority;
currActiveProcessID = i;
}
}
burstTimeCopy[currActiveProcessID] -= 1;
timeCounter++;
if (burstTimeCopy[currActiveProcessID] == 0)
{
endTime[currActiveProcessID] = timeCounter;
}
}
else //When all processes are arrived
{
unsigned maxPriority = std::numeric_limits<uint>::max();
for (std::size_t i = 0 ; i < burstTimeCopy.size(); i++)
{
if (burstTimeCopy[i] != 0 && data[i].priority < maxPriority)
{
maxPriority = data[i].priority;
currActiveProcessID = i;
}
}
timeCounter += burstTimeCopy[currActiveProcessID];
burstTimeCopy[currActiveProcessID] = 0;
endTime[currActiveProcessID] = timeCounter;
}
}
}
int main()
{
int num;
std::cout << "Enter the number of processesn";
std::cin >> num;
Priority prioritySchedule(num);
prioritySchedule.calcEndTime();
prioritySchedule.calcTurnAroundTime();
prioritySchedule.calcWaitingTime();
prioritySchedule.printInfo();
}
roundrobin.cpp
#include <iostream>
#include <vector>
#include <algorithm> // std::find
#include <iterator> // std::begin, std::end
#include <limits> //std::numeric_limits
#include "scheduling.h"
#include "roundrobin.h"
RoundRobin::RoundRobin(unsigned num, unsigned quantum): Scheduler(num)
{
timeQuantum = quantum;
}
void RoundRobin::calcEndTime()
{
//If arrival time is not sorted
//sort burst time according to arrival time
static const auto byArrival = (const Data &a, const Data &b)
{
return a.arrivalTime < b.arrivalTime;
};
std::sort(data.begin(), data.end(), byArrival);
//copy values of burst time in new vector
std::vector<unsigned> burstTimeCopy;
for (auto it = data.begin(); it != data.end(); ++it)
{
unsigned val = (*it).burstTime;
burstTimeCopy.push_back(val);
}
unsigned timeCounter = 0;
while (!(std::all_of(burstTimeCopy.begin(), burstTimeCopy.end(),
(unsigned e) { return e == 0; })))
{
unsigned currActiveProcessID = 0;
auto it = burstTimeCopy.begin();
while (it != burstTimeCopy.end())
{
if (burstTimeCopy[currActiveProcessID] > timeQuantum)
{
burstTimeCopy[currActiveProcessID] -= timeQuantum;
timeCounter += timeQuantum;
}
else if (burstTimeCopy[currActiveProcessID] > 0)
{
timeCounter += burstTimeCopy[currActiveProcessID];
burstTimeCopy[currActiveProcessID] = 0;
endTime[currActiveProcessID] = timeCounter;
}
currActiveProcessID++;
it++;
}
}
}
int main()
{
unsigned num, timeQuantum;
std::cout << "Enter number of process: ";
std::cin >> num;
std::cout << "nEnter time quantum : ";
std::cin >> timeQuantum;
RoundRobin roundRobin(num, timeQuantum);
roundRobin.calcEndTime();
roundRobin.calcTurnAroundTime();
roundRobin.calcWaitingTime();
roundRobin.printInfo();
}
c++ c++11
c++ c++11
asked Jul 2 at 13:36
coder
905932
905932
bumped to the homepage by Community♦ 10 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 10 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
At first glance, in Scheduler
, I would replace
std::vector<Data> data;
std::vector<unsigned> waitingTime;
std::vector<unsigned> turnAroundTime;
std::vector<unsigned> endTime;
by
struct Process {
Data data;
unsigned waitingTime, turnAroundTime, turnAroundTime;
};
std::vector<Process> processes;
or put the members waitingTime
turnAroundTime
turnAroundTime
in Data
directly
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
At first glance, in Scheduler
, I would replace
std::vector<Data> data;
std::vector<unsigned> waitingTime;
std::vector<unsigned> turnAroundTime;
std::vector<unsigned> endTime;
by
struct Process {
Data data;
unsigned waitingTime, turnAroundTime, turnAroundTime;
};
std::vector<Process> processes;
or put the members waitingTime
turnAroundTime
turnAroundTime
in Data
directly
add a comment |
up vote
0
down vote
At first glance, in Scheduler
, I would replace
std::vector<Data> data;
std::vector<unsigned> waitingTime;
std::vector<unsigned> turnAroundTime;
std::vector<unsigned> endTime;
by
struct Process {
Data data;
unsigned waitingTime, turnAroundTime, turnAroundTime;
};
std::vector<Process> processes;
or put the members waitingTime
turnAroundTime
turnAroundTime
in Data
directly
add a comment |
up vote
0
down vote
up vote
0
down vote
At first glance, in Scheduler
, I would replace
std::vector<Data> data;
std::vector<unsigned> waitingTime;
std::vector<unsigned> turnAroundTime;
std::vector<unsigned> endTime;
by
struct Process {
Data data;
unsigned waitingTime, turnAroundTime, turnAroundTime;
};
std::vector<Process> processes;
or put the members waitingTime
turnAroundTime
turnAroundTime
in Data
directly
At first glance, in Scheduler
, I would replace
std::vector<Data> data;
std::vector<unsigned> waitingTime;
std::vector<unsigned> turnAroundTime;
std::vector<unsigned> endTime;
by
struct Process {
Data data;
unsigned waitingTime, turnAroundTime, turnAroundTime;
};
std::vector<Process> processes;
or put the members waitingTime
turnAroundTime
turnAroundTime
in Data
directly
answered Jul 3 at 0:42
Olivier Sohn
1111
1111
add a comment |
add a comment |
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f197659%2ffollow-up-cpu-scheduling-algorithm-sjf-priority-round-robin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown