So i have to build a scheduler in priority ques, which will read infomation from test files. Also the work out the wait time and finish time. Text file will be like this;
process1 21 3
process2 23 1
process3 45 20
[processID][space][Quantum][space][priority]
So here what i have so far,
with some help from this forum have program that reads in the text file and then
stores the process id, quantum and priority.
#include <stdio.h>
int main(void)
{
const char filename[] = "file.txt";
FILE *file = fopen(filename, "r");
if ( file )
{
char line[20];
int ProcessID, Quantum, Priority;
/* Read one line at a line. */
while ( fgets(line, sizeof line, file) )
{
if ( sscanf(line, "Process%d %d %d",&ProcessID, &Quantum, &Priority) == 3 )
{
printf("Process: %d -> Quantum = %d, Priority = %d\n",ProcessID, Quantum, Priority);
}
}
fclose(file);
}
else
{
perror(filename);
}
return 0;
}
So now i have the id the quantum and the priority stored. and im abit stuck as were to start .
i believe this code will define the ques to be from 0-20
#define NUM_PRIO_QUEUES (20)
Then to get priority i think use this
priority = getpriority(PRIO_PROCESS, getpid()); // gets the priority of a process
printf("Current priority = %d\n", priority);
If the priority cant be got this error
if (getpriority == -1)
{
printf(" Error reading priority");
exit(1);
}
The idea im having now is i have to read in all the prioritys and then sort them in an order of how to do them. 0 highest priority and 20 highest.
So once iv done this i believe i may have to do a fork() to start the process, using a wait() or sleep() to the other processes untill the first is done.
Then do this for each priority.
Really what i need is abit of advice/help on if im going down the right route and anything you can advice me on??
Many thanks