Question
PLEASE HELP FIX THE MAIN METHOD BELOW: THERE ARE MANY ERRORS BEING THROWN: Use of undeclared identifier 'totalDiskDuration' Use of undeclared identifier 'cpuTime' No matching
PLEASE HELP FIX THE MAIN METHOD BELOW: THERE ARE MANY ERRORS BEING THROWN:
Use of undeclared identifier 'totalDiskDuration'
Use of undeclared identifier 'cpuTime'
No matching constructor for initialization of 'Process'
Use of undeclared identifier 'cpuRequests'
Use of undeclared identifier 'ProcessRequest'
Use of undeclared identifier 'ttyRequests'
Use of undeclared identifier 'diskRequests'
PLEASE COPY INTO IDE AND LOOK AT ERRORS
#include
#include
#include
#include
#include
using namespace std;
// Constants
const int MAX_PROCESSES = 100;
const int REAL_TIME = 0;
const int INTERACTIVE = 1;
const int READY = 2;
const int RUNNING = 3;
const int WAITING = 4;
const int TTY = 5;
const int DISK = 6;
const int CPU = 7;
// Struct to store information about each process
struct Process {
int processId;
int processClass;
int arrivalTime;
int status;
int currentTime;
int cpuTime;
int ttyTime;
int diskTime;
int deadline;
};
// Variables to keep track of state of the system
int currentTime = 0;
int realTimeProcesses = 0;
int interactiveProcesses = 0;
int completedRealTime = 0;
int missedDeadlines = 0;
int completedInteractive = 0;
int diskAccesses = 0;
int diskTime = 0;
double diskUtilization = 0;
double cpuUtilization = 0;
// Queues for process scheduling
queue
queue
queue
queue
// Function to initialize a process
void initProcess(Process &p, int processId, int processClass, int arrivalTime) {
p.processId = processId;
p.processClass = processClass;
p.arrivalTime = arrivalTime;
p.status = READY;
p.currentTime = 0;
p.cpuTime = 0;
p.ttyTime = 0;
p.diskTime = 0;
}
// Function to run a process in CPU
void runProcessInCPU(Process &p) {
p.status = RUNNING;
p.currentTime = currentTime;
cpuUtilization += p.cpuTime;
}
// Function to run a process in DISK
void runProcessInDISK(Process &p) {
p.status = WAITING;
diskAccesses++;
diskQueue.push(p);
}
// Function to run a process in TTY
void runProcessInTTY(Process &p) {
p.status = WAITING;
ttyQueue.push(p);
}
// Function to check if a process has missed its deadline
bool missedDeadline(Process &p) {
if (p.processClass == REAL_TIME && currentTime > p.deadline) {
missedDeadlines++;
return true;
}
return false;
}
// Function to print summary report
void printSummaryReport() {
cout << "Number of real-time processes that completed: " << completedRealTime << endl;
cout << "Percentage of real-time processes that missed their deadline: " << (double)missedDeadlines/realTimeProcesses * 100 << "%" << endl;
cout << "Number of interactive processes that completed: " << completedInteractive << endl;
cout << "Total number of disk accesses: " << diskAccesses << endl;
cout << "Average duration of disk access: " << totalDiskDuration/diskAccesses << " milliseconds" << endl;
cout << "Total time elapsed since start of first process: " << currentTime << " milliseconds" << endl;
cout << "CPU utilization: " << (double)cpuTime/currentTime * 100 << "%" << endl;
cout << "Disk utilization: " << (double)diskTime/currentTime * 100 << "%" << endl;
}
int main() {
gcc main.cpp;
./a.out < inputfile.txt;
int processCount = 0; // To keep track of number of processes
string processClass;
int startTime;
string resource;
int resourceTime;
while(cin >> processClass >> startTime) {
processCount++;
if(processClass == "REAL-TIME") {
int deadline;
cin >> resource >> deadline;
realTimeProcesses++;
// Adding process to real-time queue
realTimeQueue.push(Process(processCount, processClass, startTime, "READY", deadline));
}
else {
interactiveProcesses++;
// Adding process to interactive queue
interactiveQueue.push(Process(processCount, processClass, startTime, "READY"));
}
while(cin >> resource && resource != "REAL-TIME" && resource != "INTERACTIVE") {
cin >> resourceTime;
if(resource == "CPU") {
cpuRequests.push(ProcessRequest(processCount, resource, resourceTime));
}
else if(resource == "DISK") {
diskRequests.push(ProcessRequest(processCount, resource, resourceTime));
}
else if(resource == "TTY") {
ttyRequests.push(ProcessRequest(processCount, resource, resourceTime));
}
}
}
while(!realTimeQueue.empty() || !interactiveQueue.empty() || !cpuRequests.empty() || !diskRequests.empty() || !ttyRequests.empty()) {
if(cpuRequests.empty() && diskRequests.empty() && ttyRequests.empty()) {
currentTime++;
continue;
}
if(!cpuRequests.empty() && cpuRequests.front().startTime <= currentTime) {
ProcessRequest cpuReq = cpuRequests.front();
cpuRequests.pop();
int reqProcessId = cpuReq.processId;
int reqTime = cpuReq.time;
// Check if real-time process is in queue and running an interactive process
if(!realTimeQueue.empty() && runningProcess.processClass == "INTERACTIVE") {
// Preempt the interactive process and give CPU to real-time process
Process realTimeProcess = realTimeQueue.front();
realTimeQueue.pop();
runningProcess = realTimeProcess;
runningProcess.status = "RUNNING";
cout << runningProcess.processId << " " << runningProcess.processClass << " " << currentTime << endl;
}
if(runningProcess.processId == reqProcessId) {
int reqProcessId = realTimeQueue.front();
realTimeQueue.pop();
processTable[reqProcessId].status = READY;
processQueue.push(reqProcessId);
}
// Check interactive processes
while(!interactiveQueue.empty() && processTable[interactiveQueue.front()].startTime <= currentTime) {
int reqProcessId = interactiveQueue.front();
interactiveQueue.pop();
processTable[reqProcessId].status = READY;
processQueue.push(reqProcessId);
}
// Check if CPU is free
if(runningProcess.processId == -1) {
if(!processQueue.empty()) {
int reqProcessId = processQueue.front();
processQueue.pop();
processTable[reqProcessId].status = RUNNING;
runningProcess = processTable[reqProcessId];
cout << "Process " << runningProcess.processId << " " << classString[runningProcess.processClass] << " " << currentTime << endl;
}
} else {
int reqProcessId = runningProcess.processId;
int reqTime = runningProcess.cpuTime;
if(reqTime == 0) {
runningProcess.status = TERMINATED;
runningProcess.endTime = currentTime;
if(runningProcess.processClass == REAL_TIME) {
completedRealTime++;
if(runningProcess.endTime > runningProcess.deadline) {
missedDeadlines++;
}
} else {
completedInteractive++;
}
runningProcess.processId = -1;
} else {
reqTime--;
runningProcess.cpuTime = reqTime;
}
}
// Check disk requests
if(!diskQueue.empty() && diskBusy == false) {
int reqProcessId = diskQueue.front();
diskQueue.pop();
processTable[reqProcessId].status = WAITING;
diskBusy = true;
diskStartTime = currentTime;
}
if(diskBusy) {
diskTime++;
if(diskTime == DISK_TIME) {
diskBusy = false;
diskTime = 0;
int reqProcessId = diskWaitingProcess.processId;
diskWaitingProcess.status = READY;
processQueue.push(reqProcessId);
}
}
// Check TTY requests
if(!ttyQueue.empty() && ttyBusy == false) {
int reqProcessId = ttyQueue.front();
ttyQueue.pop();
processTable[reqProcessId].status = WAITING;
ttyBusy = true;
ttyStartTime = currentTime;
}
if(ttyBusy) {
ttyTime++;
if(ttyTime == TTY_TIME) {
ttyBusy = false;
ttyTime = 0;
int reqProcessId = ttyWaitingProcess.processId;
ttyWaitingProcess.status = READY;
processQueue.push(reqProcessId);
}
}
currentTime++;
}
printSummaryReport();
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started