/* Este es el procedimiento que selecciona el siguiente proceso a ejecutar */
void planificador(void)
{
        /* No le podemos quitar la CPU a un proceso mientras se está 
           atendiendo su llamada al sistema. Y hemos de cambiar de proceso 
           si el proceso está bloqueado o si ha agotado su quantum. */
        switch(current->estado) {
                case PROCESO_SYSCALL:
                        break;
                case BLOQ_TECLADO:
                        current = round_robin(current);
                        current->estado = PROCESO_RUN;
                        break;
                case PROCESO_RUN:
                        if (current->quantum)
                                break;
                        current->estado = PROCESO_LISTO;
                        current->quantum = QUANTUM;
                        current = round_robin(current);
                        current->estado = PROCESO_RUN;
			break;
		case PROCESO_KILL:
			current->estado = PCB_LIBRE;
			current = round_robin(current);
			current->estado = PROCESO_RUN;
			break;
                default:
                        ; /* situación de error */
        }
}
void main()
{
    process_details();
    //ask_process_details();
    print_details();
    calculate_totlatime();
    sort_arrivaltime();
    round_robin();
}
char* choose_and_fetch_ip(int* served_by_idx){
   #ifdef ROUND_ROBIN
   return round_robin();
   #endif
   #ifdef LEAST_CONN
   return least_conn(served_by_idx);
   #endif
   #ifdef LEAST_LATENCY
   return least_latency(served_by_idx);
   #endif
   #ifdef LEAST_LATENCY_ALT
   return least_latency_alt(served_by_idx);
   #endif
}
Beispiel #4
0
int main()
{
    int i;
    struct process proc[NUM_PROCESSES],      /* List of processes */
               proc_copy[NUM_PROCESSES]; /* Backup copy of processes */

    /* Seed random number generator */
    /*srand(time(0));*/  /* Use this seed to test different scenarios */
    srand(0xC0FFEE);     /* Used for test to be printed out */

    /* Initialize process structures */
    for(i=0; i<NUM_PROCESSES; i++)
    {
        proc[i].arrivaltime = rand()%100;
        proc[i].runtime = (rand()%30)+10;
        proc[i].priority = rand()%3;
        proc[i].starttime = 0;
        proc[i].endtime = 0;
        proc[i].flag = 0;
        proc[i].remainingtime = 0;
    }

    /* Show process values */
    printf("Process\tarrival\truntime\tpriority\n");
    for(i=0; i<NUM_PROCESSES; i++)
        printf("%d\t%d\t%d\t%d\n", i, proc[i].arrivaltime, proc[i].runtime,
               proc[i].priority);

    /* Run scheduling algorithms */
    printf("\n\nFirst come first served\n");
    memcpy(proc_copy, proc, NUM_PROCESSES * sizeof(struct process));
    first_come_first_served(proc_copy);

    printf("\n\nShortest remaining time\n");
    memcpy(proc_copy, proc, NUM_PROCESSES * sizeof(struct process));
    shortest_remaining_time(proc_copy);

    printf("\n\nRound Robin\n");
    memcpy(proc_copy, proc, NUM_PROCESSES * sizeof(struct process));
    round_robin(proc_copy);

    printf("\n\nRound Robin with priority\n");
    memcpy(proc_copy, proc, NUM_PROCESSES * sizeof(struct process));
    round_robin_priority(proc_copy);

    return 0;
}
Beispiel #5
0
int main()
{
	int requests[INPUT_SIZE];
	int i = 0;
	int num = 0;
	while(scanf("%d", &num) == 1)
	{
		if (num < 0) 
			break;
		requests[i] = num;
		i++;
	}
	first_come(requests, i);
//	short_job(requests, i);
	short_time(requests, i);
	round_robin(requests, i, 4);
	return 0;
}