int main(void) {
	int i = 0, step = 0;
	char c = ' ';
	Process* plist = NULL, *p1 = NULL;

	srand(time(NULL));

	//Inicializar escalonadores de processos
	schedInitSchedInfo();
	rrpInitSchedInfo();

	//Criando primeiro processo...
	plist = _createProcess(plist, 1, 0);
	printf("\n");

	while (c != 'n') {
		switch (i) {
			case 0:
				printf("(Passo:%d)\n", step, i);
				plist = _doRandomThings(plist);
				processDump(plist,_dumpSchedParams);
				printf("\n");
				i++;
				break;
			case SCHED_ITERATIONS+1:
				printf("(Passo:%d/Iteracoes:%d)\n", step, i-1);
				processDump(plist,_dumpSchedParams);
				step++;
				i = 0;
				printf("\nContinuar (s/n)? ");
				fflush(stdout);
				c = getchar();
				printf("\n");
				break;
			default:
				p1 = schedSchedule(plist);
//				printf("(Passo:%d/Iteracao:%d) Processo escalonado PID %d.\n", step, i, processGetPid(p1));
//				processDump(plist,_dumpSchedParams);
//				printf("\n");
				i++;
		}
	}
	return 0;
}
Example #2
0
/*
	Checks the command line arguments and activates/deactivates flags
	accordingly. Also checks for cases where the command line arguments
	are invalid.
*/
int checkArgs(int index, char *argv[], int *flags, int *values)
{	
	int foundSwitch = OFF;
	int foundSwitchEnd = OFF;
	int foundFile = OFF;
	FILE *fp;
	
	if(argv[index][0] == '-')
	{
		foundSwitch = ON;
	}
	
	if(foundSwitch == ON)
	{
		switch(argv[index][1])
		{
			case 'b':
				flags[0] = OFF;
				flags[1] = ON;
				flags[2] = OFF;
				flags[3] = OFF;
				break;
				
			case 'c':
				flags[0] = OFF;
				flags[1] = OFF;
				flags[2] = ON;
				flags[3] = OFF;
				break;
				
			case 'C':
				flags[0] = OFF;
				flags[1] = OFF;
				flags[2] = OFF;
				flags[3] = ON;
				break;
				
			case 'n':
				values[0] = checkLengthOffsetArgs(index, argv);
				flags[4] = ON;
				break;
				
			case 's':
				values[1] = checkLengthOffsetArgs(index, argv);
				flags[5] = ON;
				break;
				
			case '-':
				foundSwitchEnd = ON;
				foundSwitch = OFF;
				break;
				
			default:
				printf("Invalid\n");
				return 2;
		}
	}
	
	if((foundSwitchEnd == ON) && (argv[index+1] == NULL))
	{
		printf("Invalid");
		
		return 2;
	}
	
	/* If the switch end (--) argument is found */
	if((foundSwitchEnd == ON))
	{
		foundFile = ON;
		
		if((fp = fopen(argv[index], "r")) == 0)
		{
			perror("fopen");
		
			return 3;
		}
		
		processDump(flags, values, fp);
		
		return 0;
	}
	
	/* If the switch end (--) is not specified */
	if((foundSwitch == OFF) && (foundSwitchEnd == OFF))
	{
		foundFile = ON;
		
		if((fp = fopen(argv[index], "r")) == 0)
		{
			perror("fopen");
		
			return 3;
		}
		
		processDump(flags, values, fp);
		
		return 0;
	}
	
	return 1;
}