//***********************************
// include files
//***********************************
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cctype>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef unsigned char boolean;
//***********************************
// define directives
//***********************************
// Directive to store the minimum time slice
#define MIN_TIME_SLICE 10
// Directive to store the maximum time slice
#define MAX_TIME_SLICE 300
// Directive to store the lowest priority (*note* higher number = lower priority)
#define MIN_PRIORITY 140
// Directive to store the highest priority(*note* lower number = higher priority)
#define MAX_PRIORITY 100
// Directive to store the highest nice value(*note* lower number = nicer Process)
#define MAX_NICE = -20
// Directive to store the lowest nice value (*note* higher number = not so nice Process)
#define MIN_NICE = 19
//***********************************
// globals
//***********************************
// Clock for my scheduler
long myClock;
// Max amount of proccess in the file
int maxProcesses;
// Total turn around time for all Processes
long totalTAT;
// Total wait time for all Processes
long totalWT;
// Total CPU utiliation Time for all Processes
double totalCUT;
// The global count variables that gets used over and over again
int i, j, k;
// The global temp integer variable
int tempInt;
// class that defines what a Processes is
class ProcessContents{
public:
// constructors
ProcessContents( );
ProcessContents(ProcessContents*);
// values in a process
int pid; //pid of Process
int nice; // Processes nice value
int arrivalTime; // Processes arrival time
int numCPUBursts; // number of cpu bursts
int numIOBursts; // number of i/o bursts = #cpu bursts - 1
int totalBursts;
int endTime; // Processes end time
int priority; // priority of Process
int timeslice; // Processes timesliceSTRUCT AS A FUNCTION PARAMETER DECLARATION
int* burst; // dynamic array of cpu bursts and io bursts for the Process
void insert(ProcessContents*);
void setData(ProcessContents*);
// setters
ProcessContents* getPrev();
ProcessContents* getNext();
void setNext(ProcessContents*);
ProcessContents getData();
int getDataEl();
void reset();
void prev();
void next();
void end();
//Boolean
boolean isBeginning();
boolean isEnd();
boolean isEmpty();
private:
ProcessContents *m_next, *m_prev, *m_curr;
};
ProcessContents :: ProcessContents() {
m_prev = NULL;
m_next = NULL;
m_curr = this;
endTime = 0;
priority = 69;
timeslice = 143;
burst = NULL;
}
ProcessContents :: ProcessContents(ProcessContents* previous) {
m_prev = previous;
cout << " PRINT PREVIOUS " << previous << endl;
m_next = NULL;
priority = 96;
}
void ProcessContents::insert(ProcessContents* pNode) {
while (m_curr->getNext() != NULL)
m_curr = m_curr->getNext();
m_curr->setData(pNode);
cout << "POINTERS: "<< m_curr<< " " << m_next << " " << m_prev << endl;
m_curr->setNext(new ProcessContents(m_curr));
cout << "POINTERS AFTER: "<< m_curr<< " " << m_next << " " << m_prev << endl;
// creates the link between a newly created list and the current list
}
void ProcessContents::setData(ProcessContents* pNode) {
int z;
pid = pNode -> pid;
nice = pNode -> nice;
arrivalTime = pNode -> arrivalTime;
numCPUBursts = pNode -> numCPUBursts;
numIOBursts = pNode -> numIOBursts;
totalBursts = pNode -> totalBursts;
endTime = pNode -> endTime;
priority = pNode -> priority;
timeslice = pNode -> timeslice;
burst = new int[totalBursts];
for (z = totalBursts - 1; z >= 0; z--) {
burst[z] = pNode -> burst[z];
}
}
ProcessContents ProcessContents::getData() {
cout << "Pid: " << pid << endl;
cout << "Arrival time: " << arrivalTime << endl;
cout << "Priority: " << priority << endl;
cout << "Total Burst: " << totalBursts << endl;
}
ProcessContents* ProcessContents::getPrev() {
return m_prev;
}
ProcessContents* ProcessContents::getNext() {
return m_next;
}
void ProcessContents::setNext(ProcessContents* link) {
m_next = link;
}
void ProcessContents::reset() {
m_curr = this;
}
void ProcessContents::next() {
m_curr = m_curr->getNext();
}
void ProcessContents::prev() {
m_curr = m_curr->getPrev();
}
boolean ProcessContents::isEnd() {
return m_curr->getNext() == NULL ? 1 : 0;
}
boolean ProcessContents::isBeginning() {
return m_curr == NULL ? 1 : 0; ;
}
boolean ProcessContents::isEmpty() {
return m_curr->getNext() == m_curr->getPrev() ? 1 : 0;
}
/*
int Queue :: calculateDynPty(ProcessContents* node){
// have to adjust this part
node -> priority = (node -> priority) + (-1)*((node -> Bonus) + (node -> priority));
return (node -> priority);
}
double Queue :: calculateTimeSlice(ProcessContents *node){
node -> priority = (int)ceil((-180.0/49.0)*(double)(calculateDynPty(node))+(26900.0/49.0));
return (node -> priority);
}
*/
//***********************************
// function definitions
//***********************************
// Function that gets all the input from unix file redirection and places them into the startup queue
/*
// *****************MOST PRINT STATEMENTS*******************************
// function that prints Arrival Processes in the active queue
void printArrivalActive(Process myProcessIn);
// function that prints when a Process enters the cpu
void printEnterCPU(Process myProcessIn, int time);
// function that prints when a Process is preempted
void printPreempt(Process myProcessIn, Process myProcessOut, int time);
//function that prints when a Process is finsihed with all cpu bursts
void printFinishCPU(Process myProcessOut, int time);
// function that prints when a Process finishes a cpu burst and moves to the I/O queue
void printCPUToIO(Process myProcessOut, int time);
// funcation that prints when a Process finishes its timeslice and moves to the expired queue
void printExpiredTimeslice(Process myProcessOut, int time);
// function that prints when a Process finishes I/O burst and moves to the expired queue
void printIOToExpired(Process myProcessOut, int time);
// function that prints when a Process finishes I/O burst and moves to active queue
void printIOToActive(Process myProcessOut, int time);
// function that prints when the active and expired arrays are swapped
void printSwap(int time);
// *****************MOST CALC STATEMENTS********************************
// function that calculates Turn around time for a Process
void calcTAT(Process myProcessIn);
// fucntion that calculates Total CPU time
void calcTCT(Process myProcessIn);
// funtion that calculates Wait Time
void calcWT(Process myProcessIn);
// function that calculates percentage of CPU utilization time
void calcCUT(Process myProcessIn);
// function that calculates the average Turn around time
void calcAvgTAT();
// function that calculates the average Wait time
void calcAvgWT();
// function that calculates the average CPU utilization time
void calcAvgCUT();
*/
//***********************************
// main
//***********************************
int main() {
ProcessContents *process;
ProcessContents Startup, Active, Expired, Finished, Io, Cpu;
int numTotalBursts= 0;
// check to see if the input is specified and correct
i = 0;
// Get input from the file and load startup queue
cout << " Begin startup queue initialization " << endl;
// get the max number of Processes
cin >> maxProcesses;
process = new ProcessContents;
// Check to make sure its not the end of the file
while(cin.eof() == 0 && maxProcesses != 0) {
// give it a pid first
process -> pid = i;
i++;
cout << "pid:" << process -> pid << endl;
// get Processes nice value
cin >> process -> nice;
cout << "nice:" << process -> nice << endl;
// get Processes arrival time
cin >> process -> arrivalTime;
cout << "atime:" << process -> arrivalTime << endl;
// get Processes number of cpu bursts
cin >> process -> numCPUBursts;
cout << "#cpu bursts:" << process -> numCPUBursts << endl;
// calculate the number of io bursts ( numer of cpu bursts - 1)
process -> numIOBursts = process -> numCPUBursts - 1;
cout << "#io bursts:" << process -> numIOBursts << endl;
// get the total bursts in the process
process -> totalBursts = process -> numIOBursts + process -> numCPUBursts;
cout << "#total bursts: " << process -> totalBursts << endl;
process -> burst = new int[process -> totalBursts];
// get the cpu bursts or io bursts
for (j = process -> totalBursts - 1; j >= 0; j--) {
cin >> process -> burst[j];
cout << "Burst: " << j << " is " << process-> burst[j] << " long." << endl;
} // end of read for bursts
Startup.insert(process);
} // end of read for an entire file
cout << " Done initilizing startup queue " << endl;
for(; !Startup.isBeginning(); Startup.prev())
Startup.getData();
return 0;
}
//***********************************
// functions
//***********************************
/*
// function that prints Arrival Processes in the active queue
void printArrivalActive(Process myProcessIn) {
}
// function that prints when a Process enters the cpu
void printEnterCPU(Process myProcessIn, int time) {
}
// function that prints when a Process is preempted
void printPreempt(Process myProcessIn, Process myProcessOut, int time) {
}
//function that prints when a Process is finsihed with all cpu bursts
void printFinishCPU(Process myProcessOut, int time) {
}
// function that prints when a Process finishes a cpu burst and moves to the I/O queue
void printCPUToIO(Process myProcessOut, int time) {
}
// funcation that prints when a Process finishes its timeslice and moves to the expired queue
void printExpiredTimeslice(Process myProcessOut, int time) {
}
// function that prints when a Process finishes I/O burst and moves to the expired queue
void printIOToExpired(Process myProcessOut, int time) {
}
// function that prints when a Process finishes I/O burst and moves to active queue
void printIOToActive(Process myProcessOut, int time) {
}
// function that prints when the active and expired arrays are swapped
void printSwap(int time) {
}
// function that calculates Turn around time for a Process
void calcTAT(Process myProcessIn) [
}
// fucntion that calculates Total CPU time
void calcTCT(Process myProcessIn) {
}
// funtion that calculates Wait Time
void calcWT(Process myProcessIn) {
}
// function that calculates percentage of CPU utilization time
void calcCUT(Process myProcessIn) {
}
// function that calculates the average Turn around time
void calcAvgTAT() {
}
// function that calculates the average Wait time
void calcAvgWT() {
}
// function that calculates the average CPU utilization time
void calcAvgCUT() {
}
*/