I
iwasinnihon
I am sure that I am missing something but I cannot get the following
code to work. It doesn't even make it to my test printf statement
before I get a segmentation fault. Does anyone have any ideas why I
can't get this to run?
void srtn(int atime[10], int ctime[10])
{
int running = 0;
int queue[15];
int wait[11];
int turnaround[11];
int i, j;
printf("This is a test");
for(i = 0; i < 11; i++)
{
wait = 0;
turnaround = 0;
}
queue[0] = 0;
queue[1] = -1;
int size = 1;
i = 0;
while(queue != -1)
{
ctime[queue]--;
running++;
for(j = i+1; queue[j] != -1; j++)
wait[queue[j]]++;
for(j = 0; j < 10; j++)
if(atime[j] != -1)
if(atime[j] <= running)
{
queue[size] = j;
queue[size+1] = -1;
size++;
}
turnaround[queue]++;
if(ctime[queue] == 0);
atime[queue] = -1;
for(j = 0; j < size; j++)
if(atime[queue[j]] != -1)
if(ctime[queue[j]] < ctime[queue])
i = j;
}
for(i = 0; i < 10; i++)
turnaround += wait;
for(i = 0; i < 10; i++)
{
wait[10] += wait;
turnaround[10] += turnaround;
}
wait[10] = wait[10] / 10;
turnaround[10] = turnaround[10] / 10;
print_report(wait, turnaround);
}
code to work. It doesn't even make it to my test printf statement
before I get a segmentation fault. Does anyone have any ideas why I
can't get this to run?
void srtn(int atime[10], int ctime[10])
{
int running = 0;
int queue[15];
int wait[11];
int turnaround[11];
int i, j;
printf("This is a test");
for(i = 0; i < 11; i++)
{
wait = 0;
turnaround = 0;
}
queue[0] = 0;
queue[1] = -1;
int size = 1;
i = 0;
while(queue != -1)
{
ctime[queue]--;
running++;
for(j = i+1; queue[j] != -1; j++)
wait[queue[j]]++;
for(j = 0; j < 10; j++)
if(atime[j] != -1)
if(atime[j] <= running)
{
queue[size] = j;
queue[size+1] = -1;
size++;
}
turnaround[queue]++;
if(ctime[queue] == 0);
atime[queue] = -1;
for(j = 0; j < size; j++)
if(atime[queue[j]] != -1)
if(ctime[queue[j]] < ctime[queue])
i = j;
}
for(i = 0; i < 10; i++)
turnaround += wait;
for(i = 0; i < 10; i++)
{
wait[10] += wait;
turnaround[10] += turnaround;
}
wait[10] = wait[10] / 10;
turnaround[10] = turnaround[10] / 10;
print_report(wait, turnaround);
}