Exemple #1
0
// ---------- MAIN ----------
int main(int argc, char *argv[])
{
	// variable declerations
	int i = 0;			// holds page values
	size_t buffersize = 0;		// for getline to allocate
	ssize_t read;			// status of getline
	char *line = NULL;		// holds a line from stdin
	int cacheSize = atoi(argv[1]);	// takes cache size given as command line parameter
	int requestCount[cacheSize];	// holds the number of times a page is requested
	int cache[cacheSize];		// holds the pages in memory
	for (i = 0; i < cacheSize; ++i)	// initialize cache and requestCount to 0
		cache[i] = requestCount[i] = 0;
	// get lines of input  from stdin
	while((read = getline(&line, &buffersize, stdin)) != -1)
	{
		// valid input starts with a digit
		if(isdigit(line[0]))
		{
			requests++;
			i = strtol(line, NULL, 10); 	// convert valid number from string to base 10 int
			lfu(i, requestCount, cache, cacheSize);// call LRU function
		}
	}

	fprintf(stdout, "%d\n%d\n", requests, faults);

	return 0;
}
//TODO dynamically maintain all array sizes
int main(int argc, char** argv) {

	int fr_no=5, s=0;
	char rep_policy[20] = "FIFO";
	char logpath[1024] = "input.txt";

	for (s=1; s<argc; s++) {
		if (strcmp(argv[s], "-f")==0) {
			fr_no = atoi(argv[++s]);
		} else if (strcmp(argv[s], "-r")==0) {
			strcpy(rep_policy, argv[++s]);
		} else if (strcmp(argv[s], "-i")==0) {
			strcpy(logpath, argv[++s]);
		} else if (strcmp(argv[s], "-h")==0) {
			printf("help mode");
			serverOptions();
		} else {
			printf("\n\nNo Options Passed, ...\n");
		}
	}
	
	int i, j=0,nf=0;
	if(fr_no>0){
		nf=fr_no;
	}
	else{
		printf("Enter proper frame value\n");
		exit(0);
	}
	unsigned int input[16] ={0,1,2,3,0,1,2,3,0,1,2,3,4,5,6,7};//{1,2,3,4,1,2,5,1,2,3,4,5};
	count_page=0;
				//{ 1, 2, 3, 1, 1, 2, 4, 1, 3, 2, 1, 3 };// //TODO load the array size from file inputs
	
	//Reading from file
	FILE *f;
			char res[1024];
			f = fopen(logpath,"r");

			if (f == NULL) {perror ("Error opening file..Exiting...\n");exit(0);}
			else {
				fgets(res,1024,f);
				//puts(res);
				char* str=NULL;
				char delim[] = " ";
				str=strtok(res,delim);
					while(str!=NULL) {						
						input[i]=atoi(str);
						i++;
						count_page++;						
						str = strtok(NULL," ");
					}
			}
				printf("%d %s %s\n", fr_no, rep_policy, logpath);
	if (strcmp(rep_policy,"LRU-REF8")==0) {
		printf("Executing LRU-Ref8\n");
		pr1=lruRefBit(input, nf);
		pr2 = optim(input, nf);
		compare(rep_policy);
		return 0;
	}
	/*else if(==2){
	 optim(input,nf);
	 return 0;
	 }*/
	else if (strcmp(rep_policy,"LRU-STACK")==0) {
		printf("Executing LRU-STACK\n");
		pr1= lruStack(input, nf);
		pr2 = optim(input, nf);
		compare(rep_policy);
		return 0;
	} else if (strcmp(rep_policy,"LFU")==0) {
		printf("Executing LFU\n");
		pr1=lfu(input, nf);
		pr2 = optim(input, nf);
		compare(rep_policy);
		return 0;
	} else if (strcmp(rep_policy,"LRU-CLOCK")==0) {
		pr1 = lruref8bit(input,nf);
		pr2 = optim(input, nf);
		compare(rep_policy);
	} else {
		pr1 = fifo(input, nf);
		pr2 = optim(input, nf);
		compare(rep_policy);
		return 0;
	}
}