1. Imagine that there are processes that are being generated at random intervals
ID: 3766758 • Letter: 1
Question
1. Imagine that there are processes that are being generated at random intervals, each process has an id (0001 to 9999) and in addition each process has a complexity score that is directly proportional to the product of its required memory and its expected run time. We can treat the complexity score (c >= 0) as a random value with a mean of 5 and a standard deviation of 1. As the processes are generated they are placed into a queue of length q (q is user input). Processes are removed from the front of the queue after they have been in the front for c time steps. IF a process is generated and the queue if full then the overload is placed in a separate priority queue with the lowest c score given the highest priority. When room is made in the process queue, it is refilled from the priority queue. Generate a simulation of this process handler.
Time
Queue
New Processes P-id(c)
Priority Queue
1
< >
P1(3) P2(1)
< >
2
<P1, P2>
P3(4)
< >
3
<P1,P2,P3>
None
< >
4
<P2,P3>
P5(1)
etc
22
<P44(2), P45, …P54>
P55(3), P56(1)
< >
23
<P44(2), P45,…P54>
P57(2)
<P56, P55>
24
<P44(2) P45, P54>
None
<P56, P57, P55>
etc
<P45, P54, …P54, P56>
None
<P57, P55>
Time
Queue
New Processes P-id(c)
Priority Queue
1
< >
P1(3) P2(1)
< >
2
<P1, P2>
P3(4)
< >
3
<P1,P2,P3>
None
< >
4
<P2,P3>
P5(1)
Explanation / Answer
#include <iostream>
#include "priorityQ.cpp"
#include "queue.cpp"
using namespace std;
int main()
{
cout<<endl<<"Enter the Queue length: ";
int q_length;
cin>>q_length;
int memory=20;
Q Queue(q_length);
priorityQueue PQ;
int PID;
int i=0;
int complexity_score;
while(i<12)
{
/*if Q not full, insert process in it*/
if(!Queue.isFull())
{
Queue.enQ(PID);
}
else
//if Queue is full
//insert process in priority Queue
PQ.insert(c,PID);
if(memory>0)
{
complexity_score = (rand()%5)+1;
// if process elapses 3 times in front of Queue
if(complexity_score>3)
{
//remove the process from Queue, for memory execution
int process=Queue.deQ();
cout<<"Process "<<process<<" is executed";
memory--;
//remove processes from PQ, and insert in Q
if(!Queue.isFull())
{
int pp=PQ.extractMin();
Queue.enQ(pp);
}
}
}
if(memory==0)
{
memory=20;
}
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.