| | |
Simplified Computer(CS): escalonamento algorithms, FCFS, SJP, Round-Robin [was: Help]
![]() |
•
•
Join Date: Apr 2006
Posts: 3
Reputation:
Solved Threads: 0
Simplified Computer(CS): escalonamento algorithms, FCFS, SJP, Round-Robin [was: Help]
0
#1 Apr 30th, 2006
Hello,
I am with problems I need to Implement urgent a Simplified Computer (CS). This computer will receive as entrance parameter the configuration of duration and it arrives of processes, according to example to proceed.
Process
1
2
3
Arrival
1
2
3
Duration
5
2
4
After receiving the configurations of the processes, CS will owe emular/simular the escalonamento and execution of these processes, and, at the end of the execution CS should exhibit the time of return and of wait of each process (Silberschatz), according to the table to proceed:
Process Return Waits
Its CS should be capable to work the escalonamento algorithms, FCFS, SJP, Round-Robin.
Could anybody help me?
I am with problems I need to Implement urgent a Simplified Computer (CS). This computer will receive as entrance parameter the configuration of duration and it arrives of processes, according to example to proceed.
Process
1
2
3
Arrival
1
2
3
Duration
5
2
4
After receiving the configurations of the processes, CS will owe emular/simular the escalonamento and execution of these processes, and, at the end of the execution CS should exhibit the time of return and of wait of each process (Silberschatz), according to the table to proceed:
Process Return Waits
Its CS should be capable to work the escalonamento algorithms, FCFS, SJP, Round-Robin.
Could anybody help me?
Re: Simplified Computer(CS): escalonamento algorithms, FCFS, SJP, Round-Robin [was: Help]
0
#2 Apr 30th, 2006
•
•
Join Date: Apr 2006
Posts: 3
Reputation:
Solved Threads: 0
Re: Simplified Computer(CS): escalonamento algorithms, FCFS, SJP, Round-Robin [was: Help]
0
#3 Apr 30th, 2006
Look the code below, he is considered that the processes arrive in the instant 0, and I need you make them to consider the arrival in aleatory times, that is to say, time of different arrival.
And precise to implement the SJF preemptive and not preemptive.
Will it be that can help me? I will be very grateful.
And precise to implement the SJF preemptive and not preemptive.
C Syntax (Toggle Plain Text)
/* Simulador de Escalonamento de Processos*/ #include <stdio.h> #include <stdlib.h> /* Estrutura */ struct processos { int id; /* Identifição do processo*/ int surto; /* Tempo de duração do processo*/ int prioridade; int execucao; /* Tempo de execução do processo*/ int espera; /* Tempo de espera do processo*/ struct processos *prox; }; /* Declarações de Protótipo de função */ struct processos *init_processos (int id, int surto, int prioridade); void fcfs (struct processos *proc); void listprocs (struct processos *proc); void prioridade (struct processos *proc); void rr (struct processos *proc, int quantum); void sjf (struct processos *proc); int main (void) { struct processos *plist, *ptmp; plist = init_processos(1, 10, 3); plist->prox = init_processos(2, 1, 1); ptmp = plist->prox; ptmp->prox = init_processos(3, 2, 3); ptmp = ptmp->prox; ptmp->prox = init_processos(4, 1, 4); ptmp = ptmp->prox; ptmp->prox = init_processos(5, 5, 2); /* Simulações executadas*/ listprocs(plist); fcfs(plist); sjf(plist); prioridade(plist); rr(plist, 1); while (plist != NULL) { ptmp = plist; plist = plist->prox; free(ptmp); }; return(0); }; /* Inicialização de entrada da lista de processos*/ struct processos *init_processos (int id, int surto, int prioridade) { struct processos *proc; proc = (struct processos*)malloc(sizeof(struct processos)); if (proc == NULL) { printf("Erro Fatal: Falha Alocacao de memoria.\nFinalizar.\n"); exit(1); }; proc->id = id; proc->surto = surto; proc->prioridade = prioridade; proc->execucao = 0; proc->espera = 0; proc->prox = NULL; return(proc); }; /* Escalonamento FCFS - o primeiro que chega /* é o primeiro a sair, ou seja, será executado primeiro */ void fcfs (struct processos *proc) { int tempo = 0, inicio, fim; struct processos *tmp = proc; printf("\tEscalonamento FCFS\n"); printf("\n"); while (tmp != NULL) { inicio = tempo; tempo += tmp->surto; fim = tempo; printf("Processo: %d\tSurto: %d\tEspera: %d\tRetorno: %d\n", tmp->id, tempo, inicio, fim); tmp = tmp->prox; }; printf("\n\n"); }; /* Listando Processos */ void listprocs (struct processos *proc) { struct processos *tmp = proc; printf("\tListagem de Processos\n"); printf("\n"); while (tmp != NULL) { printf("Processo: %d\tPrioridade: %d\tSurto: %d\n", tmp->id, tmp->prioridade, tmp->surto); tmp = tmp->prox; }; printf("\n\n"); }; /* Simulação de Processos por Prioridade * Obs: O processo de menor valor de prioridade obtem * prioridade maior na fila de processos */ void prioridade (struct processos *proc) { int tempo, inicio, fim, maior; struct processos *copia, *tmpsrc, *tmp, *maiorprimeiro; printf("\tEscalonamento por Prioridade\n"); printf("\n"); /* Replicando Lista de Processos */ tmpsrc = proc; copia = tmp = NULL; while (tmpsrc != NULL) { if (copia == NULL) { copia = init_processos(tmpsrc->id, tmpsrc->surto, tmpsrc->prioridade); tmp = copia; } else { tmp->prox = init_processos(tmpsrc->id, tmpsrc->surto, tmpsrc->prioridade); tmp = tmp->prox; }; tmpsrc = tmpsrc->prox; }; /* Programa Principal */ tempo = 0; while (copia != NULL) { /* Localiza o proximo processo */ maiorprimeiro = NULL; maior = copia->prioridade; tmp = copia->prox; tmpsrc = copia; while (tmp != NULL) { if (tmp->prioridade < maior) { maior = tmp->prioridade; maiorprimeiro = tmpsrc; }; tmpsrc = tmp; tmp = tmp->prox; }; if (maiorprimeiro == NULL) { /* Verifica se o primeiro processo possui maior prioridade */ inicio = tempo; tempo += copia->surto; fim = tempo; printf("Processo: %d\tSurto: %d\tEspera: %d\tRetorno: %d\n", copia->id, tempo, inicio, fim); tmpsrc = copia->prox; free(copia); copia = tmpsrc; } else { /* Verifica se o primeiro processo não possui maior prioridade */ tmp = maiorprimeiro->prox; inicio = tempo; tempo += tmp->surto; fim = tempo; printf("Processo: %d\tSurto: %d\tEspera: %d\tRetorno: %d\n", tmp->id, tempo, inicio, fim); maiorprimeiro->prox = tmp->prox; free(tmp); }; }; printf("\n\n"); }; /* Escalonamento Round-Robin */ void rr (struct processos *proc, int quantum) { int jobsremain, passes; struct processos *copia, *tmpsrc, *tmp, *slot; printf("\tEscalonamento Round-Robin - Quantum: %d)\n", quantum); printf("\n"); tmpsrc = proc; copia = tmp = NULL; while (tmpsrc != NULL) { if (copia == NULL) { copia = init_processos(tmpsrc->id, tmpsrc->surto, tmpsrc->prioridade); tmp = copia; } else { tmp->prox = init_processos(tmpsrc->id, tmpsrc->surto, tmpsrc->prioridade); tmp = tmp->prox; }; tmpsrc = tmpsrc->prox; }; /* Programa rotina de análise de prioridade */ jobsremain = 2; slot = NULL; while (jobsremain) { jobsremain = 0; /* Seleciona o próximo processo efetuando sua alocação */ if (slot == NULL) { slot = copia; jobsremain = 2; } else { passes = 0; do { if (slot->prox == NULL) { passes++; slot = copia; } else { slot = slot->prox; }; } while (passes <= 3 && slot->surto == slot->execucao); if (passes <= 3) { jobsremain = 2; }; }; /* Executa um ciclo */ tmp = copia; while (tmp != NULL) { if (tmp->surto > tmp->execucao) { if (tmp == slot) { tmp->execucao += quantum; } else { tmp->espera += quantum; }; }; tmp = tmp->prox; }; }; /* Exibe os resultados e elimina as replicações */ tmp = copia; while (tmp != NULL) { printf("Processo: %d\tSurto: %d\tEspera: %d\tRetorno: %d\n", tmp->id, tmp->surto, tmp->espera, tmp->execucao + tmp->espera); tmpsrc = tmp; tmp = tmp->prox; free(tmpsrc); }; printf("\n"); }; /* Escalonamento SJF*/ void sjf (struct processos *proc) { int tempo, inicio, fim, shortest; struct processos *copia, *tmpsrc, *tmp, *beforeshortest; printf("\tEscalonamento SJF\n"); printf("\n"); /* Lista de processos é replicada */ tmpsrc = proc; copia = tmp = NULL; while (tmpsrc != NULL) { if (copia == NULL) { copia = init_processos(tmpsrc->id, tmpsrc->surto, tmpsrc->prioridade); tmp = copia; } else { tmp->prox = init_processos(tmpsrc->id, tmpsrc->surto, tmpsrc->prioridade); tmp = tmp->prox; }; tmpsrc = tmpsrc->prox; }; tempo = 0; while (copia != NULL) { /* Encontra o proximo processo*/ beforeshortest = NULL; shortest = copia->surto; tmp = copia->prox; tmpsrc = copia; while (tmp != NULL) { if (tmp->surto < shortest) { shortest = tmp->surto; beforeshortest = tmpsrc; }; tmpsrc = tmp; tmp = tmp->prox; }; /* Executa processo e remove ráplica da lista de processos */ if (beforeshortest == NULL) { /* Aloca o primeiro processo caso o mesmo seja menor */ inicio = tempo; tempo += copia->surto; fim = tempo; printf("Processo: %d\tSurto: %d\tEspera: %d\tRetorno: %d\n", copia->id, tempo, inicio, fim); tmpsrc = copia; copia = copia->prox; free(tmpsrc); } else { /* Aloca o primeiro processo caso não haja /*ocorrencia de outro menor */ tmp = beforeshortest->prox; inicio = tempo; tempo += tmp->surto; fim = tempo; printf("Processo: %d\tSurto: %d\tEspera: %d\tRetorno: %d\n", tmp->id, tempo, inicio, fim); beforeshortest->prox = tmp->prox; free(tmp); }; }; printf("\n\n"); };
Will it be that can help me? I will be very grateful.
Last edited by Dave Sinkula; Apr 30th, 2006 at 11:09 pm.
Re: Simplified Computer(CS): escalonamento algorithms, FCFS, SJP, Round-Robin [was: H
0
#4 May 1st, 2006
Help with what?
Are you expecting people to just take your code and debug it for you and hand it back to you? That's not likely to happen.
I mean, if you have a specific question like
- why doesn't this line compile, or
- why does it crash with some type of input, or
- I don't understand how to...
Then that's fairly easy to answer.
You seem to have the bulk of the code there, and on superficial inspection it seems to be doing the right thing.
You could clean up the warnings a bit I suppose
Are you expecting people to just take your code and debug it for you and hand it back to you? That's not likely to happen.
I mean, if you have a specific question like
- why doesn't this line compile, or
- why does it crash with some type of input, or
- I don't understand how to...
Then that's fairly easy to answer.
You seem to have the bulk of the code there, and on superficial inspection it seems to be doing the right thing.
You could clean up the warnings a bit I suppose
C Syntax (Toggle Plain Text)
$ gcc -W -Wall -ansi -pedantic -O2 bar.c bar.c:42: warning: ISO C does not allow extra ‘;’ outside of a function bar.c:58: warning: ISO C does not allow extra ‘;’ outside of a function bar.c:61:1: warning: "/*" within comment bar.c:75: warning: ISO C does not allow extra ‘;’ outside of a function bar.c:87: warning: ISO C does not allow extra ‘;’ outside of a function bar.c:148: warning: ISO C does not allow extra ‘;’ outside of a function bar.c:212: warning: ISO C does not allow extra ‘;’ outside of a function bar.c:260:17: warning: "/*" within comment bar.c:272: warning: ISO C does not allow extra ‘;’ outside of a function
![]() |
Similar Threads
Other Threads in the C Forum
- Previous Thread: creating random numbers
- Next Thread: Help! C program w/Pointer Notation to Convert Text
| Thread Tools | Search this Thread |
* adobe ansi api array asterisks binarysearch calculate centimeter char character cm convert copyanyfile copyimagefile copypdffile cprogramme createcopyoffile createprocess() csyntax directory feet fflush fgets file floatingpointvalidation fork frequency givemetehcodez global gtkgcurlcompiling gtkwinlinux hacking highest homework i/o inches infiniteloop input interest intmain() iso keyboard kilometer km linked linkedlist linux linuxsegmentationfault list locate lowest match meter microsoft mqqueue mysql number oddnumber odf open opendocumentformat openwebfoundation owf pattern pdf performance posix power probleminc program programming pyramidusingturboccodes read recv recvblocked repetition reversing scanf scheduling segmentationfault send single socketprograming socketprogramming stack standard string suggestions systemcall unix urboc user variable voidmain() wab whythiscodecausesegmentationfault win32api windows.h windowsapi






