Ok i half have a working scheduler. The idea is to print out input from a text file,
with the process id quantum and priority, sort them out into priority order, 0-20(0 highest) ad print them out the number of times the quatum is.
here is what i have so far
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
char filename[256];
strcpy(filename, argv[1]);
FILE *file = fopen(filename, "r");
int ProcessID, Quantum, Priority;
if ( file )
{
char line[20];
if fgets(line, sizeof line, file) ) //reads in line at time
{
sscanf(line, "Process%d %d %d",&ProcessID, &Quantum, &Priority) == 3; //assigns input to process id, quatum and priority//
}
}
else
{
printf("Error: Unable to open file"); //error
}
////////////////////////////////////////////////////////////////////////////////////////////////////
int i = 1;
if(Priority == 0) // do this if the priority is 0 (highest)
{
while(i <= Quantum)
{
printf("Process id %d -> Quantum No %d -> Quantum Total %d->Priority %d\n",ProcessID,i,Quantum,Priority); //print out info number of times the quatum is
i++;
}
}
else
{
printf("\nNo Priority %d processes\n\n",Priority); // if is no input data on certain priority
}
if(Priority == 1)
{
while(i <= Quantum)
{
printf("Process id %d -> Quantum No %d -> Quantum Total %d->Priority %d\n",ProcessID,i,Quantum,Priority); //prints out number of times
i++;
}
}
else
{
printf("\nNo Priority %d processes\n\n",Priority);
}
fclose(file);
return 0;
}
//would carry on with if(prioity == 2) { do } all way to 20.
The problem im getting is when i run it only prints out the first line of the text file.
if i run first part ( above the line of ////) with a printf statement it will print out all info in the text file.
So im thinking i need to store ProcessID, Quantum, Priority in some kind of buffer or array or something along those lines??? I just dont now how to get this working!
also once this is working i need to print the contents of priority as round robin,
e.g
process 1 proirty 0
process 2 priority 0
process 1 priority 0
process 2 priority 0
etc......
anyone have any suggustions would be greatful :)