Simplified Computer(CS): escalonamento algorithms, FCFS, SJP, Round-Robin [was: Help]

Reply

Join Date: Apr 2006
Posts: 3
Reputation: regbrz is an unknown quantity at this point 
Solved Threads: 0
regbrz regbrz is offline Offline
Newbie Poster

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?
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Simplified Computer(CS): escalonamento algorithms, FCFS, SJP, Round-Robin [was: Help]

 
0
  #2
Apr 30th, 2006
So what's the question?

How to read the file?

One thing to work on is some kind of process table, and 3 functions (doFCFS, doRoundRobin etc) which work on that process table.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 3
Reputation: regbrz is an unknown quantity at this point 
Solved Threads: 0
regbrz regbrz is offline Offline
Newbie Poster

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.

  1. /* Simulador de Escalonamento de Processos*/
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. /* Estrutura */
  5. struct processos {
  6. int id; /* Identifição do processo*/
  7. int surto; /* Tempo de duração do processo*/
  8. int prioridade;
  9. int execucao; /* Tempo de execução do processo*/
  10. int espera; /* Tempo de espera do processo*/
  11. struct processos *prox;
  12. };
  13. /* Declarações de Protótipo de função */
  14. struct processos *init_processos (int id, int surto, int prioridade);
  15. void fcfs (struct processos *proc);
  16. void listprocs (struct processos *proc);
  17. void prioridade (struct processos *proc);
  18. void rr (struct processos *proc, int quantum);
  19. void sjf (struct processos *proc);
  20.  
  21. int main (void) {
  22.  
  23. struct processos *plist, *ptmp;
  24. plist = init_processos(1, 10, 3);
  25. plist->prox = init_processos(2, 1, 1); ptmp = plist->prox;
  26. ptmp->prox = init_processos(3, 2, 3); ptmp = ptmp->prox;
  27. ptmp->prox = init_processos(4, 1, 4); ptmp = ptmp->prox;
  28. ptmp->prox = init_processos(5, 5, 2);
  29. /* Simulações executadas*/
  30. listprocs(plist);
  31. fcfs(plist);
  32. sjf(plist);
  33. prioridade(plist);
  34. rr(plist, 1);
  35.  
  36. while (plist != NULL) {
  37. ptmp = plist;
  38. plist = plist->prox;
  39. free(ptmp);
  40. };
  41. return(0);
  42. };
  43. /* Inicialização de entrada da lista de processos*/
  44. struct processos *init_processos (int id, int surto, int prioridade) {
  45. struct processos *proc;
  46. proc = (struct processos*)malloc(sizeof(struct processos));
  47. if (proc == NULL) {
  48. printf("Erro Fatal: Falha Alocacao de memoria.\nFinalizar.\n");
  49. exit(1);
  50. };
  51. proc->id = id;
  52. proc->surto = surto;
  53. proc->prioridade = prioridade;
  54. proc->execucao = 0;
  55. proc->espera = 0;
  56. proc->prox = NULL;
  57. return(proc);
  58. };
  59.  
  60. /* Escalonamento FCFS - o primeiro que chega
  61. /* é o primeiro a sair, ou seja, será executado primeiro */
  62. void fcfs (struct processos *proc) {
  63. int tempo = 0, inicio, fim;
  64. struct processos *tmp = proc;
  65. printf("\tEscalonamento FCFS\n");
  66. printf("\n");
  67. while (tmp != NULL) {
  68. inicio = tempo;
  69. tempo += tmp->surto;
  70. fim = tempo;
  71. printf("Processo: %d\tSurto: %d\tEspera: %d\tRetorno: %d\n", tmp->id, tempo, inicio, fim);
  72. tmp = tmp->prox;
  73. };
  74. printf("\n\n");
  75. };
  76.  
  77. /* Listando Processos */
  78. void listprocs (struct processos *proc) {
  79. struct processos *tmp = proc;
  80. printf("\tListagem de Processos\n");
  81. printf("\n");
  82. while (tmp != NULL) {
  83. printf("Processo: %d\tPrioridade: %d\tSurto: %d\n", tmp->id, tmp->prioridade, tmp->surto);
  84. tmp = tmp->prox;
  85. };
  86. printf("\n\n");
  87. };
  88. /* Simulação de Processos por Prioridade
  89.  * Obs: O processo de menor valor de prioridade obtem
  90.  * prioridade maior na fila de processos */
  91. void prioridade (struct processos *proc) {
  92. int tempo, inicio, fim, maior;
  93. struct processos *copia, *tmpsrc, *tmp, *maiorprimeiro;
  94. printf("\tEscalonamento por Prioridade\n");
  95. printf("\n");
  96.  
  97. /* Replicando Lista de Processos */
  98. tmpsrc = proc;
  99. copia = tmp = NULL;
  100. while (tmpsrc != NULL) {
  101. if (copia == NULL) {
  102. copia = init_processos(tmpsrc->id, tmpsrc->surto, tmpsrc->prioridade);
  103. tmp = copia;
  104. } else {
  105. tmp->prox = init_processos(tmpsrc->id, tmpsrc->surto, tmpsrc->prioridade);
  106. tmp = tmp->prox;
  107. };
  108. tmpsrc = tmpsrc->prox;
  109. };
  110. /* Programa Principal */
  111. tempo = 0;
  112. while (copia != NULL) {
  113.  
  114. /* Localiza o proximo processo */
  115. maiorprimeiro = NULL;
  116. maior = copia->prioridade;
  117. tmp = copia->prox;
  118. tmpsrc = copia;
  119. while (tmp != NULL) {
  120. if (tmp->prioridade < maior) {
  121. maior = tmp->prioridade;
  122. maiorprimeiro = tmpsrc;
  123. };
  124. tmpsrc = tmp;
  125. tmp = tmp->prox;
  126. };
  127. if (maiorprimeiro == NULL) {
  128. /* Verifica se o primeiro processo possui maior prioridade */
  129. inicio = tempo;
  130. tempo += copia->surto;
  131. fim = tempo;
  132. printf("Processo: %d\tSurto: %d\tEspera: %d\tRetorno: %d\n", copia->id, tempo, inicio, fim);
  133. tmpsrc = copia->prox;
  134. free(copia);
  135. copia = tmpsrc;
  136. } else {
  137. /* Verifica se o primeiro processo não possui maior prioridade */
  138. tmp = maiorprimeiro->prox;
  139. inicio = tempo;
  140. tempo += tmp->surto;
  141. fim = tempo;
  142. printf("Processo: %d\tSurto: %d\tEspera: %d\tRetorno: %d\n", tmp->id, tempo, inicio, fim);
  143. maiorprimeiro->prox = tmp->prox;
  144. free(tmp);
  145. };
  146. };
  147. printf("\n\n");
  148. };
  149. /* Escalonamento Round-Robin */
  150. void rr (struct processos *proc, int quantum) {
  151. int jobsremain, passes;
  152. struct processos *copia, *tmpsrc, *tmp, *slot;
  153. printf("\tEscalonamento Round-Robin - Quantum: %d)\n", quantum);
  154. printf("\n");
  155. tmpsrc = proc;
  156. copia = tmp = NULL;
  157. while (tmpsrc != NULL) {
  158. if (copia == NULL) {
  159. copia = init_processos(tmpsrc->id, tmpsrc->surto, tmpsrc->prioridade);
  160. tmp = copia;
  161. } else {
  162. tmp->prox = init_processos(tmpsrc->id, tmpsrc->surto, tmpsrc->prioridade);
  163. tmp = tmp->prox;
  164. };
  165. tmpsrc = tmpsrc->prox;
  166. };
  167. /* Programa rotina de análise de prioridade */
  168. jobsremain = 2;
  169. slot = NULL;
  170. while (jobsremain) {
  171. jobsremain = 0;
  172. /* Seleciona o próximo processo efetuando sua alocação */
  173. if (slot == NULL) {
  174. slot = copia;
  175. jobsremain = 2;
  176. } else {
  177. passes = 0;
  178. do {
  179. if (slot->prox == NULL) {
  180. passes++;
  181. slot = copia;
  182. } else {
  183. slot = slot->prox;
  184. };
  185. } while (passes <= 3 && slot->surto == slot->execucao);
  186. if (passes <= 3) {
  187. jobsremain = 2;
  188. };
  189. };
  190. /* Executa um ciclo */
  191. tmp = copia;
  192. while (tmp != NULL) {
  193. if (tmp->surto > tmp->execucao) {
  194. if (tmp == slot) {
  195. tmp->execucao += quantum;
  196. } else {
  197. tmp->espera += quantum;
  198. };
  199. };
  200. tmp = tmp->prox;
  201. };
  202. };
  203. /* Exibe os resultados e elimina as replicações */
  204. tmp = copia;
  205. while (tmp != NULL) {
  206. printf("Processo: %d\tSurto: %d\tEspera: %d\tRetorno: %d\n", tmp->id, tmp->surto, tmp->espera, tmp->execucao + tmp->espera);
  207. tmpsrc = tmp;
  208. tmp = tmp->prox;
  209. free(tmpsrc);
  210. };
  211. printf("\n");
  212. };
  213.  
  214. /* Escalonamento SJF*/
  215. void sjf (struct processos *proc) {
  216. int tempo, inicio, fim, shortest;
  217. struct processos *copia, *tmpsrc, *tmp, *beforeshortest;
  218. printf("\tEscalonamento SJF\n");
  219. printf("\n");
  220. /* Lista de processos é replicada */
  221. tmpsrc = proc;
  222. copia = tmp = NULL;
  223. while (tmpsrc != NULL) {
  224. if (copia == NULL) {
  225. copia = init_processos(tmpsrc->id, tmpsrc->surto, tmpsrc->prioridade);
  226. tmp = copia;
  227. } else {
  228. tmp->prox = init_processos(tmpsrc->id, tmpsrc->surto, tmpsrc->prioridade);
  229. tmp = tmp->prox;
  230. };
  231. tmpsrc = tmpsrc->prox;
  232. };
  233. tempo = 0;
  234. while (copia != NULL) {
  235. /* Encontra o proximo processo*/
  236. beforeshortest = NULL;
  237. shortest = copia->surto;
  238. tmp = copia->prox;
  239. tmpsrc = copia;
  240. while (tmp != NULL) {
  241. if (tmp->surto < shortest) {
  242. shortest = tmp->surto;
  243. beforeshortest = tmpsrc;
  244. };
  245. tmpsrc = tmp;
  246. tmp = tmp->prox;
  247. };
  248. /* Executa processo e remove ráplica da lista de processos */
  249. if (beforeshortest == NULL) {
  250. /* Aloca o primeiro processo caso o mesmo seja menor */
  251. inicio = tempo;
  252. tempo += copia->surto;
  253. fim = tempo;
  254. printf("Processo: %d\tSurto: %d\tEspera: %d\tRetorno: %d\n", copia->id, tempo, inicio, fim);
  255. tmpsrc = copia;
  256. copia = copia->prox;
  257. free(tmpsrc);
  258. } else {
  259. /* Aloca o primeiro processo caso não haja
  260.   /*ocorrencia de outro menor
  261.   */
  262. tmp = beforeshortest->prox;
  263. inicio = tempo;
  264. tempo += tmp->surto;
  265. fim = tempo;
  266. printf("Processo: %d\tSurto: %d\tEspera: %d\tRetorno: %d\n", tmp->id, tempo, inicio, fim);
  267. beforeshortest->prox = tmp->prox;
  268. free(tmp);
  269. };
  270. };
  271. printf("\n\n");
  272. };


Will it be that can help me? I will be very grateful.
Last edited by Dave Sinkula; Apr 30th, 2006 at 11:09 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

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
  1. $ gcc -W -Wall -ansi -pedantic -O2 bar.c
  2. bar.c:42: warning: ISO C does not allow extra ‘;’ outside of a function
  3. bar.c:58: warning: ISO C does not allow extra ‘;’ outside of a function
  4. bar.c:61:1: warning: "/*" within comment
  5. bar.c:75: warning: ISO C does not allow extra ‘;’ outside of a function
  6. bar.c:87: warning: ISO C does not allow extra ‘;’ outside of a function
  7. bar.c:148: warning: ISO C does not allow extra ‘;’ outside of a function
  8. bar.c:212: warning: ISO C does not allow extra ‘;’ outside of a function
  9. bar.c:260:17: warning: "/*" within comment
  10. bar.c:272: warning: ISO C does not allow extra ‘;’ outside of a function
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC