Ejemplo n.º 1
0
int main(int argc, char *argv[]) {
    FILE *fp;
    int blocklist[MAX_JOBS];
    int number;
    int i = 0;
    if (argc == 2){
        fp = fopen(argv[1], "r");
    }
     else { 
         fp = stdin;
     }
    while( fscanf(fp, "%d", &number) > 0)
    {
      blocklist[i] = number;
      
        i++;
        
    }
    
    printf("Assignment 6: Block Access Algorithm");
    printf("\nBy: Nikki Talley, Chad Rasmussen and Josh Chevrier");
    printf("\n");
    fcfs(blocklist, i);
    sstf(blocklist, i);
    look(blocklist, i);
    cLook(blocklist, i);
     return 0;
 }
Ejemplo n.º 2
0
int main() {

  pptr head=NULL;
  pptr tail=NULL;
  int i=0;
  int tpid,tarr_time,tburst_time;
  pptr tprocess;
  FILE *read;
  read=fopen("input","r");
  write=fopen("write","w");
  trace=fopen("trace","w");
  for(i=1;i<=3;i++) {
    //fscanf(read,"%d",&tpid);
    tpid=++g_pid;
    fscanf(read,"%d",&tarr_time);
    fscanf(read,"%d",&tburst_time);
    tprocess=create_process(tpid,tarr_time,tburst_time);
    add_to_queue(&head,&tail,tprocess);
  } fclose(read);

  fcfs(head,tail);



  return 0;


}
Ejemplo n.º 3
0
void choice()
{
	clrscr();
	i=nor;
	movt=0;
	int ch;
	cout<<"1.FCFS\n2.SSTF\n3.SCAN\n4.LOOK\n5.CSCAN\n6.CLOOK\n7.Exit\nEnter Choice : ";
	cin>>ch;
	switch(ch)
	{
		case 1:fcfs();
			break;
		case 2:sstf();
			break;
		case 3:scan();
			break;
		case 4:look();
			break;
		case 5:cscan();
			break;
		case 6:clook();
			break;
		default:exit(1);
	}
}
Ejemplo n.º 4
0
static auto bindSimulator(EAlgorithms algorithm)
{
    switch (algorithm)
    {
        case EAlgorithms::FCFS:
            {
                AlgorithmSimulator fcfs(std::bind(&Algorithms::FCFS, std::placeholders::_1, std::placeholders::_2));
                return fcfs;
            }
        case EAlgorithms::RR:
            {
                AlgorithmSimulator rr(std::bind(&Algorithms::RR, std::placeholders::_1, std::placeholders::_2));
                return rr;
            }
        case EAlgorithms::PQ:
            {
                AlgorithmSimulator pq(std::bind(&Algorithms::PriorityQueue, std::placeholders::_1, std::placeholders::_2));
                return pq;
            }
        case EAlgorithms::SJK:
            {
                AlgorithmSimulator sjk(std::bind(&Algorithms::SJK, std::placeholders::_1, std::placeholders::_2));
                return sjk;
            }
        default:
            throw std::logic_error("Invalid algorithm...");
    }
}
Ejemplo n.º 5
0
void main()
{
	clrscr();
	cout << "Enter the Number of Process : ";
	cin >> n;

	cout << "\n\n1) FCFS   2) SJF   3) SRTF   4) RR\n\n";
	cout << "Enter Your Choice : ";
	cin >> choice;

	cout << "\n";
	int i;
	for(i=0;i<n;i++)
	{
	cout << "Arrival Time & Service Time for Process " << i+1 << " : ";
	tab[i][0]=i+1;
	cin >> tab[i][1];
	cin >> tab[i][2];
	}
	ttt=totaltime();
	switch(choice)
	{
		case '1': fcfs();break;
		case '2': sjf();break;
		case '3': srtf();break;
		case '4': rr();break;
		default : exit(0);
	}

}
Ejemplo n.º 6
0
int main(int argc, char** argv) {
    
   float totale; 
   int MoT;                                                

   menu();
   
   printf("[1]Totale\t[2]Media\t[0]Exit\n");
   scanf("%d",&MoT);
   
   if (!MoT)
       exit(EXIT_SUCCESS);
   
   totale = fcfs(MoT);
   
   if (totale >= 0)
       printf("Il tempo di attesa è: %5.2f\n",totale);
   else if (totale == -2)
       printf("Error!Incorrect number of processes");
   else if (totale == -1)
       printf("Error! Invalid MoT\n");
   else if (totale == -3)
       printf("Error! Invalid execution time value");
    return (EXIT_SUCCESS);
}
Ejemplo n.º 7
0
int Program::exec()
{
	std::vector<unsigned int> positions;
	Random rand;

	for (unsigned long r = ReadsCount_; r > 0; r--)
		positions.push_back(rand.next(1, Config_.getInt("Head", "MaxPos", 1) - 1));
	DS_.add(positions);

	Disk fcfs(Config_.getInt("Head", "InitPos", 1));
	Disk sstf(Config_.getInt("Head", "InitPos", 1));
	Disk scan(Config_.getInt("Head", "InitPos", 1));
	CSCANDisk cscan(Config_.getInt("Head", "InitPos", 1), Config_.getInt("Head", "MaxPos", 1));

	std::cout << "FCFS \t\t SSTF \t\t SCAN \t\t CSCAN" << std::endl;
	do
	{
		fcfs.setNextPosition(DS_.popFCFS());
		sstf.setNextPosition(DS_.popSSTF());
		scan.setNextPosition(DS_.popSCAN());
		cscan.setNextPosition(DS_.popCSCAN());

		std::string str = "";
		str += fcfs.toString() + " \t ";
		str += sstf.toString() + " \t ";
		str += scan.toString() + " \t ";
		str += cscan.toString();
		std::cout << str << std::endl;
		Log_.out(str);
	}
	while (!DS_.done());
	std::cin.get();
	return 0;
}
Ejemplo n.º 8
0
int main(){
	mythread_init();
	struct mythread_t t1, t2;
	mythread_create(&t1, test, 0);
	mythread_create(&t2, test2, 0);
	fcfs();
	printf("all threads completed\n");
}
Ejemplo n.º 9
0
void main()
{
	int ch,n,i;
	struct process p[20];
	printf("\nEnter number of processes: ");
	scanf("%d",&n);	
	accept(p,n);
	for(i=0;i<n;i++)
		p[i].flag=0;
	fcfs(p,n);	
}
Ejemplo n.º 10
0
int main()
{
    input();
    printf("%d\n\n\n",clook());
    printf("%d\n\n\n",cscan());
    printf("%d\n\n\n",fcfs());
    printf("%d\n\n\n",look());
    printf("%d\n\n\n",scan());
    printf("%d\n\n\n",sstf());
    return 0;
}
Ejemplo n.º 11
0
Archivo: fcfs.c Proyecto: vsbranjan/gh
int main()
{
	static int size;		

	printf("Enter the total number of processes: ");
	scanf("%d", &size);

	if(size == 0)	goto empty_queue;	
	fcfs(size);				/* first come first serve */

	return 0;		

	empty_queue:	printf("\nProcess queue is empty. End of run.\n");
}
Ejemplo n.º 12
0
int main(void)
{
	int frameSize, i = 0;
	char file[32], *requests = NULL, ch;
	FILE *fp;
	initscr();
	werase(stdscr);
	getmaxyx(stdscr, maxy, maxx);
	mvprintw(maxy/2 - 1, (maxx - 40)/2, "Enter the name of file to be read: ");
	scanw("%s", file);
	if((fp = fopen(file, "r")) == NULL)
	{
		mvprintw(maxy/2 + 1, (maxx - 20) / 2, "Error opening file!!!");
		getch();
		endwin();
		return -1;
	}
	ch = getc(fp);
	while(ch != EOF)
	{
		i++;
		requests = (char *) realloc(requests, sizeof(char) * i);
		requests[i - 1] = ch;
		ch = getc(fp);
	};
	requests = (char *) realloc(requests, sizeof(char) * (i+1));
	requests[i] = '\0';
	fclose(fp);

	mvprintw(maxy/2 + 1, (maxx - 30) / 2, "Enter the number of frames: ");
	scanw("%d", &frameSize);
	while(1)
	{
		switch(menu())
		{
			case 1: fcfs(requests, frameSize);
				break;

			case 2: lru(requests, frameSize);
				break;

			case 3: optimal(requests, frameSize);
				break;

			case 4: endwin();
				return 0;
		}
	}
	return 0;
}
bankers(int t)
{
    int count1 = 0, count2 = 0,i , j,k, n=0;
    int safe[15];
    printf("\n");
    printf("\nSafe Sequence is:- \t");
    while(count1!=process)
    {
    count2=count1;
    for(i=0;i<process;i++)
    {
       for(j=0;j<resource;j++)
       {
            if(need[i][j]<=avail[j])
            {
                 k++;
            }
        }
        if(k==resource && completed[i]==0 )
        {
           safe[n] = i;
           n++;
           printf("P[%d]\t",p[i]);
           completed[i]=1;
           for(j=0;j<resource;j++)
           {
               avail[j]=avail[j]+allot[i][j];
           }
           count1++;
         }
         k=0;
    }
         if(count1==count2)
         {
         printf("\t\t Stop ..After this.....Deadlock \n");
            break;
         }
    }

    printf("\n");
     for(i=0;i<3;i++)
    {
        for(j=0;j<process;j++)
            printf("%d\t",ans[i][j]);
        printf("\n");
    }
    if(count1!=count2)
        fcfs(safe);
}
Ejemplo n.º 14
0
int setup_scheduler(const char* input_file, const char* scheduler, int sec_to_sec_seek, int end_to_end_seek){
	char** tokens = read_input(input_file);
	int len = array_len(tokens);
	access_data* data[len];
	char* tok;
	char* line;

	int i = 0;
	while (i < len){
		line = tokens[i];
		tok = strtok(line," ");

		int arrival_time = atoi((const char*)tok);
    	tok = strtok(NULL," ");
    	int sector = atoi((const char*)tok);

		access_data* a = malloc(sizeof(access_data));
		new_data(a, arrival_time, sector);
		data[i] = a;

		i++;
	}

	//show_data(data, len);

	if (strcmp(scheduler, "FCFS") == 0){
		fcfs(data, len, sec_to_sec_seek);
	}
	else if (strcmp(scheduler, "SSTN") == 0){
		sstn(data, len, sec_to_sec_seek);
	}
	else if (strcmp(scheduler, "SCAN") == 0){
		scan(data, len, sec_to_sec_seek);
	}
	else if (strcmp(scheduler, "CSCAN") == 0){
		cscan(data, len, sec_to_sec_seek);
	}
	else{
		fprintf(stderr, "%s\n","Invalid scheduling algorithm.");
		exit(EXIT_FAILURE);
	}

	free_access_data(data, len);
	free(tokens);

	return 0;
}
Ejemplo n.º 15
0
int main (void )
{
  int valor;

  printf ("Digite um escalonamento: \n\n");
  printf ("1) FCFS \n");
  printf ("2) SJF \n");
  printf ("3) SRTF \n");
  printf ("4) ROUND ROBIN \n");
  printf ("5) MULTINIVEL \n");
  printf ("6) SAIR \n\n");
  scanf("%d", &valor);

  switch ( valor )
  {
     case 1 :
       fcfs();
     break;

     case 2 :
       sjf();;
     break;

     case 3 :
        srtf();;
     break;

     case 4 :
        roundrobin();
     break;

     case 5 :
        multinivel();
     break;

     case 6 :
        printf ("\nFim.\n");
     break;

     default :
       printf ("Valor invalido!\n");
  }

  return 0;
}
Ejemplo n.º 16
0
/*
**policy_handler select the corresponding function to handle the request sequence
**@ncylinder is the total number of cylinders
**@ipolicy is the index if policy
**@ifile is the file pointer to the input_file
**@result is a pointer to dynamic array for store execute sequence and their travel_num
**@travel is the total travel number
*/
void policy_handler(int ncylinder, int ipolicy, FILE *ifile, int **result, int *travel)
{
	int *list = NULL;
	init_sequence(ncylinder, ifile, &list);
	init_result(result);
	item *sorted = NULL;
	int first = list[0];

	//sort the request according to there distance to the head of disk
	if (ipolicy == 2 || ipolicy == 3 || ipolicy == 4)
		 sorted = sort(ncylinder, list);
	if (ipolicy == 1)
		*travel = fcfs(ncylinder, list, *result);
	else if (ipolicy == 2)
		*travel = sstf(first, sorted, *result);
	else if (ipolicy == 3)
		*travel = cscan(ncylinder, first, sorted, *result);
	else if (ipolicy == 4)
		*travel = look(ncylinder, first, sorted, *result);

}
Ejemplo n.º 17
0
int main(int argc, char *argv[])
{
	int choice;

	if (argc != 2)
	{
		fprintf(stderr, "Usage: [%s] + num_process\n", argv[0]);
	}

	while (true)
	{
		menu_show();
		scanf("%d", &choice);

		switch(choice)
		{
			case 1:
				priority_create(atoi(argv[1]));
				priority();
				break;
			case 2:
				fcfs_create(atoi(argv[1]));
				fcfs();
				break;
			case 3:
				sjf_create(atoi(argv[1]));
				sjf();
				break;
			case 0:
				printf("退出程序...\n");
				break;
			default:
				printf("选择错误,请重新选择!\n");
				break;
		}	
		if (choice == 0)
			break;
	}
	return EXIT_SUCCESS;
}
Ejemplo n.º 18
0
int main() {
	//init the root node of the Process list
	struct Process* rootProcess = 0;
	
	//init the Process pointer which will traverse the list
	struct Process* current = 0;
	
	//init variables to hold information about process list
	char policy[15];
	int quantum;
	
	//init the file stream
	FILE *fp;
	fp = fopen("input.txt", "r");
	
	// Read the input file and create the list of Process nodes
	char *policyLine = readLineFromFile(fp);
	sscanf(policyLine, "%s %d", policy, &quantum);
	free(policyLine); policyLine = 0;
		
	// Read the list of processes until we see a newline or eof
	char *nextProcessLine = readLineFromFile(fp);
	while(strcmp(nextProcessLine, "\n") != 0)
	{
		int id, arrive, duration, priority;
		if(sscanf(nextProcessLine, "%d %d %d %d", &id, &arrive, &duration, &priority) != 4)
		{
			// If sscanf returned something other than 4, we didn't get a complete line - skip this process
			fprintf(stderr, "Error: process line incomplete, skipping it.\n");
		}
		else
		{
			// We got a complete line - build a Process struct and add it to the list
			if(current == 0) // this is the root node
			{
				rootProcess = malloc(sizeof(struct Process));
				current = rootProcess;
			}
			else
			{
				current->next = malloc(sizeof(struct Process));
				current = current->next;
			}

			current->id = id;
			current->arrive = arrive;
			current->duration = duration;
			current->priority = priority;
			current->next = 0;
		}

		// Read the next line
		free(nextProcessLine); nextProcessLine = 0;
		if(feof(fp) || ferror(fp))
			break;
		nextProcessLine = readLineFromFile(fp);
	}
	if(nextProcessLine)
		free(nextProcessLine); nextProcessLine = 0;

	// If there were no processes in the file, proceed no further.
	if(current == 0)
	{
		fprintf(stderr, "No processes specified - exiting.\n");
		exit(1);
	}
	
	// Print out the list of processes -- for debugging
	// (Uncomment from here to the end of the while-loop if you want a little more verbose output.)
	/*printf("\nThe schedule policy is as follows: %s \n", policy);
	printf("The quantum for the policy is: %d \n", quantum);
	printf("The input file has provided these processes:\n");
	current = rootProcess;
	while (current != 0) {
		printf("P%d: ", current->id);
		printf( "id: %d ", current->id);
		printf( "arrive: %d ", current->arrive);
		printf( "duration: %d ", current->duration);
		printf( "priority: %d \n", current->priority);
		current = current->next;
	}*/
	
	int wait = 0;
	int turnaround = 0;
	int downTime = 0;

	struct cpuSlot *slots;
	
	if (strcmp(policy, "fcfs") == 0) {
		slots = fcfs(rootProcess, quantum, &downTime);
		printf("%d ", totalTime(slots));  
		printf("%d \n", totalTime(slots) + downTime);
		int count = 0;
		while (slots != 0) {
			printf("%d ", slots->procId);
			printf( "%d ", slots->startTime);
			printf( "%d ", slots->end);
			printf( "%d ", slots->turnaround);
			turnaround += slots->turnaround;
			printf( "%d \n", slots->wait);
			wait += slots->wait;
			slots = slots->next;
			count++;
		}
		printf("%f ", (float)turnaround/(float)count);
		printf("%f \n", (float)wait/(float)count);
	} else if (strcmp(policy, "rr") == 0) {
		slots = rr(rootProcess, quantum, &downTime);
		printf("%d ", totalTime(slots));
		printf("%d \n", totalTime(slots) + downTime);
		int count = 0;
		while (slots != 0) {
			printf("%d ", slots->procId);
			printf("%d ", slots->startTime);
			printf("%d ", slots->end);
			printf("%d ", slots->turnaround);
			turnaround += slots->turnaround;
			printf( "%d \n", slots->wait);
			wait += slots->wait;
			slots = slots->next;
			count++;
		}
		printf("%f ", (float)turnaround/(float)count);
		printf("%f \n", (float)wait/(float)count);
	} else if (strcmp(policy, "priority_non") == 0) {
		slots = priority_non(rootProcess, quantum, &downTime);
		printf("%d ", totalTime(slots));  
		printf("%d \n", totalTime(slots) + downTime);
		int count = 0;
		while (slots != 0) {
			printf("%d ", slots->procId);
			printf( "%d ", slots->startTime);
			printf( "%d ", slots->end);
			printf( "%d ", slots->turnaround);
			turnaround += slots->turnaround;
			printf( "%d \n", slots->wait);
			wait += slots->wait;
			slots = slots->next;
			count++;
		}
		printf("%f ", (float)turnaround/(float)count);
		printf("%f \n", (float)wait/(float)count);
	} else if (strcmp(policy, "priority") == 0) {
		slots = priority(rootProcess, quantum, &downTime);
		printf("%d ", totalTime(slots));  
		printf("%d \n", totalTime(slots) + downTime);
		int count = 0;
		while (slots != 0) {
			printf("%d ", slots->procId);
			printf( "%d ", slots->startTime);
			printf( "%d ", slots->end);
			printf( "%d ", slots->turnaround);
			turnaround += slots->turnaround;
			printf( "%d \n", slots->wait);
			wait += slots->wait;
			slots = slots->next;
			count++;
		}
		printf("%f ", (float)turnaround/(float)count);
		printf("%f \n", (float)wait/(float)count);
	} else {
		printf("The schedule policy in the input file is invalid\n");
	}

	// Deallocate the process and CPU-slot lists
	for(struct Process *p = rootProcess; p != 0; )
	{
		struct Process *toDelete = p;
		p = p->next;
		free(toDelete);
	}
	rootProcess = 0;
	for(struct cpuSlot *p = slots; p != 0; )
	{
		struct cpuSlot *toDelete = p;
		p = p->next;
		free(toDelete);
	}
	slots = 0;
	
	return 0;
}
Ejemplo n.º 19
0
int main(int argc, char **argv)
{

	FILE * inputf;
	if (argc == 3)
	{
		verbose = 1;
		inputf = fopen(argv[2], "r");
	}
	else if (argc == 2)
	{
		verbose = 0;
		inputf = fopen(argv[1], "r");
	}

	random_ints = fopen(RANDOM_INTS, "r");
	int pool_sz;
	int a;
	int b;
	int c;
	int io;
	fscanf(inputf, "%d", &pool_sz);
	int p_ind;
	process pool[pool_sz];
	process pool_copy[pool_sz];
	process sorted_pool[pool_sz];
	process sorted_copy[pool_sz];
	process proc;


	int state[pool_sz];

	char * list_output;
	char * process_format = " ( %d %d %d %d )";
	printf("The original input was: %d", pool_sz);
	for (p_ind = 0; p_ind < pool_sz; p_ind ++)
	{
		fscanf(inputf, process_format, &a, &b, &c, &io);
		asprintf(&list_output, process_format, a, b, c, io);
		printf(list_output);
		proc = init_process(p_ind, a, b, c, io);
		pool[p_ind] = proc;	
		sorted_pool[p_ind] = proc;	
		state[p_ind] = UNSTARTED;
	}
	printf("\n");

	qsort(sorted_pool, pool_sz, sizeof(process), process_cmp);
	printf("The (sorted) input is: %d", pool_sz);
	for (p_ind = 0; p_ind < pool_sz; p_ind ++)
	{
		proc = sorted_pool[p_ind];
		asprintf(&list_output, process_format, proc.arrival_time, proc.cpu_burst_gen, proc.cpu_time_left, proc.io_burst_gen);
		printf(list_output);
	}
	printf("\n\n");


	list_output = NULL;
	process_format = NULL;

	memcpy(pool_copy, pool, sizeof(process) * pool_sz);
	memcpy(sorted_copy, sorted_pool, sizeof(process) * pool_sz);
	uni(state, pool_copy, sorted_copy, pool_sz);
	fclose(random_ints);
	random_ints = fopen(RANDOM_INTS, "r");


	int i = 0;
	for (i = 0; i < pool_sz; i ++)
	{
		state[i] = UNSTARTED;
	}	
	memcpy(pool_copy, pool, sizeof(process) * pool_sz);
	fcfs(state, pool_copy, pool_sz);
	fclose(random_ints);
	random_ints = fopen(RANDOM_INTS, "r");

	for (i = 0; i < pool_sz; i ++)
	{
		state[i] = UNSTARTED;
	}	
	memcpy(pool_copy, pool, sizeof(process) * pool_sz);
	sjf(state, pool_copy, pool_sz);
	fclose(random_ints);
	random_ints = fopen(RANDOM_INTS, "r");

	for (i = 0; i < pool_sz; i ++)
	{
		state[i] = UNSTARTED;
	}	
	memcpy(pool_copy, pool, sizeof(process) * pool_sz);
	roundrobin(2, state, pool_copy, pool_sz);

	fclose(random_ints);

	return 0;
}
Ejemplo n.º 20
0
int main()

{



int ch,i,n;

printf("enter the number of processes\n");

scanf("%d",&n);

for(i=0;i<n;i++)

{

printf("enter process id\n");

scanf("%d",&p[i].pid);

printf("enter the arrival time\n");

scanf("%d",&p[i].at);

printf("enter the service time\n");

scanf("%d",&p[i].bt);

}

do

{

printf("1.fcfs \n2.sjf non-premptive\n3.sjf premptive\n");

printf("enter choice\n");

scanf("%d",&ch);

if(ch==1)

{

fcfs(n);

gantt(p,n);

display(p,n);

}

if(ch==2)

{

nsjf(n);

gantt(p,n);

display(p,n);

}

if(ch==3)

{

         psjf(n);

         }

}while(ch!=4);

return 0;

}