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;
}
The problem was somewhere else in my code. I was forking off parents instead of children, and this was causing multiple parents to run in the background. I fixed the code and now it's working.