Ejemplo n.º 1
0
int main(int argc, char *argv[]) {
 	int i, rc, n = 0;
 	pthread_t threads[MAX_SIZE];

 	nprocs   = sysconf(_SC_NPROCESSORS_ONLN); // numero de processadores do sistema 
 	gstart   = clock();
 	nthreads = 0;
 	dflag 	 = 0;
 	
 	for (i = 0; i < MAX_SIZE; i++) 
 		flags[i] = 0;
	play = 1;
 	if (argc >= 4) {   // parametros: 1- numero do escalonador 2- nome do arquivo trace 3- nome do arquivo a ser criado
  		if (argc == 5) //			  4- (opcional) caracter d
  			if (strcmp(argv[4], "d") == 0)
  				dflag = 1;
  				
  		readTraceFile(argc, argv[2], &n, procs);

		switch (*argv[1]) {
			case '1':
				firstCome(n, threads);
				break;
			case '2':
			//	shortestJob(n, threads);
				break;
			case '3':
				printf("Shortest Remaining Time Next.\n");
				break;
			case '4':
				printf("Round-Robin.\n");
				break;
			case '5':
				printf("Escalonamento com Prioridade.\n");
				break;
			case '6':
				printf("Escalonamento em Tempo Real com Deadlines Rigidos.\n");
				break;
			default:
				printf("Escalonador Escolhido Incorreto.\n");
				exit(EXIT_FAILURE);
		}
	}
	else {
		printf("Numero incorreto de parametros.\n");
		exit(EXIT_FAILURE);
	}
	for (i = 0; i < n; i++) { //esperando as threads terminarem
		rc = pthread_join(threads[i], NULL);
		assert(0 == rc);
	}
	writeTraceFile(argv[3], n, procs, 0);
 	for (i = 0; i < n; i++)
 		free(procs[i].name);
 	pthread_mutex_destroy(&mutex);
 	pthread_cond_destroy(&cond);
 	return 0;
}	
Ejemplo n.º 2
0
/**	Handles the algorithm selection, depending on which scheduling method was specified via the command line
	@param	inputfile The name of the input file containing the processes
	@param	algorithm The desired schedulaing algorithm
	@param	quantum	The desired time quantum (for round robin scheduling only)
	@param 	expire The time at which the memory state is cloned for printing to the output file
	@param 	mode The program mode. 0 represents Scheduler mode, 1 represents Virtual Memory mode	
*/
void scheduler(char **inputfile, char **algorithm, int *quantum, int *expire,int *mode) {
	int length;

	process **proc = readFile(*inputfile, &length, mode);

	// Sort the processes and enqueue.
	QUEUE *pqueue = sort(proc, length);
	
	// Prepare and output file.
	FILE *file;
	if((file = fopen("out.file","w")) == NULL)
	{
		printf("Failed to create/open the file\n");
		return;
	}
	
	// Algorithm selection
	if(strcmp(*algorithm, "FCFS") == 0) 
	{
		firstCome(pqueue,expire,mode);
	}
	else if(strcmp(*algorithm, "RR") == 0)
	{
		roundRobin(pqueue, *quantum,expire,mode);
	}
	else if(strcmp(*algorithm, "SRT") == 0)
	{
		shortestRemaining(pqueue,expire,mode);
	}
	else if(strcmp(*algorithm, "SPN") == 0)
	{
		shortestNext(pqueue,expire,mode);
	}
	
	//prepare and print to the memory output file if the mode suggests to do so
	if(*mode == 1) {
		//append all virtual memory and page table data to the file
		printPage();
	}
	
	fclose(file);	
	return;
}