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

Ok another idea, if i just simply do a
if (priority == 0)
{

then here i can run a sched_fifo,
run all these processes in priority que 0
exit
}
do the same for 1 , then 2 then 3 etc........


sound good?


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

OK now im thinking similar type thing


do a
if(priority == 0)
{
int setpriority(int which, int who, int prio); ( set the priority of whole group to 0)
}

do this for each one up to 20.

then do a get_priority to get the highest group of process and

then do a fork()
pid_t fork(void);
to run them.

for each group of processes

Will this work if i can get it working or there a better way to do this?
or any advice help?????????????

anyone???????????

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.