I have an integer called:
int pID = 0;
Inside my while loop I'm using pID++; to increment it. Sometimes the pID doesn't get incremented and sometimes it will. My sample output would be.
0
1
2
2
2
3
4
5
5
6
7
Does anyone have an idea to why it would be doing this?
Here is the code.
int main(int argv, char *argc[])
{
srand(time(NULL));
totalRunningTime = clock();
int randomP;
int pID = 0;
int ran = 0;
int tempA;
FILE * filePt;
while(true)
{
randomP = rand() % 2;
pID++;
printf("%i\n",pID);
if(randomP == 0)// Creates a process
{
queue(pID,0,0);
}
tempA = q[head].getAffinity();
if (q[head].getPID() > -1)// give cores a process
{
switch(tempA)
{
case 0:CPU(tempA);
case 1:CPU(tempA);
case 2:CPU(tempA);
case 3:CPU(tempA);
}
}
//S; //sleep
// Determine process fate
ran = rand() % 3;
switch(ran)
{
case 0: killProcess(); // process terminates and is removed from the system.
case 1:
{
if(isQueueEmpty() == 0)// Make sure queue isn't empty
queue(pop());//1 – process returns to the ready queue to wait its turn
}
case 2:
{
if(isQueueEmpty() == 0)// Make sure queue isn't empty
io(pop());//2 – process requires I/O and goes into the I/O queue.
}
}
}
return 0;
}