int main() { matrix m, orig; matrix eigen_vectors; int size, c; printf("Enter matrix from: (1) file, (2) keyboard, (3) gilbert? "); scanf("%d", &c); switch (c) { case 1: inputFileMatrix(m, &size); break; case 2: keybordMatrix(m, &size); break; case 3: hilbertMatrix(m, &size); break; default: return 0; } printf("Output: (1) file, (2) display? "); scanf("%d", &c); if (c == 1) { FILE * output; output = fopen("output.txt","w"); stdout = output; } printf("\nInput matrix"); printMatrix(m, size); copyMatrix(orig, m, size); setIdentityMatrix(eigen_vectors, size); int iterations = roundRobin(m, eigen_vectors, size); printf("\n------------------------------------"); printf("\nAmount iterations: %d\n", iterations); printf("\nEigenvalues:\n"); printDiagonal(m, size); printf("\nEigenvectors:"); printMatrix(eigen_vectors, size); if (c != 1) analysisOfResults(m, orig, eigen_vectors, size); return 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; }
int main() { int n,i,quanta; float awt,atat; process pr[20]; printf("\nEnter the no. of processes:"); scanf("%d",&n); for(i=0; i<n; i++) { printf("\nEnter the arrival and burst time of process %d: ",i+1); pr[i].id=i; pr[i].queued=No; scanf("%d %d",&pr[i].arr,&pr[i].bt); } printf("\nEnter the time quanta: "); scanf("%d",&quanta); roundRobin(pr,n,quanta,&awt,&atat); printf("\nThe average waiting(AWT)=%.2f",awt); printf("\nThe average turnaround time(ATAT)=%.2f\n",atat); return 0; }
int main(int argc,char *argv[]) { char filename[20],output_file[20]; FILE *fp; char proc[20]; int map[10][5]={{0}}; int proc_no=0,n; int sch_type,i=0; if(argc==3) { strcpy(filename,argv[1]); sch_type=*argv[2]-'0'; } else { printf("Invalid number of arguments\n"); return 0; } fp=fopen(filename,"r"); if(fp==NULL) { printf("File not found\n"); return 0; } n=strlen(filename); while(i<n && filename[i]!='.') { output_file[i]=filename[i]; i++; } strcat(output_file,"-"); strcat(output_file,argv[2]); strcat(output_file,".txt"); fclose(fp); reformatFile(filename); fp=fopen(filename,"r"); while(!(feof(fp))) { strcpy(proc,""); fgets(proc,20,fp); n=strlen(proc); if(n!=0) { generateMap(map,proc,proc_no); proc_no++; } } fclose(fp); switch(sch_type) { case 0 : firstComeFirstServe(map,proc_no,output_file); break; case 1 : roundRobin(map,proc_no,output_file);break; case 2 : shortestRemainingJobFirst(map,proc_no,output_file); break; default : printf("Invalid type of scheduling selection"); } printf("Output written to the file %s",output_file); printf("\n"); return 0; }