1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
| program ordonnanceur;
program ordonnanceur;
uses crt;
label 0,5;
type listebi=^cellule;
interval='A'..'Z';
enregis=record
id :integer;
duree :real;
priorite :interval
end;
cellule=record
precedent:listebi;
info :enregis;
suivant :listebi
end;
var liste,l:listebi;
dur:real;
prt:char;
brancher:0..10;
choix,i,id:integer;
fin,passer:boolean;
procedure insertion(var liste:listebi;ptval,p:listebi;passer:boolean);
{insere un processus à la position envoyée en paramètre par la procedure positionadequate}
begin
if ptval<>nil then
begin
p^.suivant:=ptval;
p^.precedent:=ptval^.precedent;
if ptval=liste then
begin
liste:=p;
if passer=false then
ptval^.suivant:=p;
end
else
p^.precedent^.suivant:=p;
ptval^.precedent:=p
end
end;
procedure positionadequate(var liste:listebi;prt:interval;dur:real;id:integer);
var p,preced,position:listebi;fini:boolean;
begin
new (p);
p^.info.duree:=dur;
p^.info.priorite:=prt; {remplissage des champs du processus en cours de creation et d'ajout}
p^.info.id:=id;
if (liste=nil) then
begin
liste:=p;
p^.suivant:=p; {insertion du premier processus de la liste d'attente}
p^.precedent:=p;
end
else
begin
position:=liste;
fini:=false;
passer:=true;
while ((not(fini)) and (p^.info.priorite < position^.info.priorite)) do
begin
preced:=position;
position:=position^.suivant; {positionnement du nouvel element dans le même ordre de priorité}
fini:=position=liste
end;
if fini=true then
begin
{insertion du nouvel element en fin de liste}
p^.suivant:=liste;
p^.precedent:=preced;
preced^.suivant:=p;
liste^.precedent:=p
end
else
begin
if (p^.info.priorite>position^.info.priorite) then
begin
{insertion du nouveau processus au milieu ou en tete de la liste}
insertion(liste,position,p,passer);
end
else
begin
{p^.info.priorite=postion^.info.priorite}
fini:=false;
passer:=false;
while ((p^.info.duree>position^.info.duree) and (not(fini))) do
begin
position:=position^.suivant;
passer:=position<>liste;
fini:=(position^.info.priorite=p^.info.priorite)
end;
if ((passer=false) and (p^.info.duree>position^.info.duree))then
begin
p^.suivant:=liste;
p^.precedent:=liste;
liste^.suivant:=p;
liste^.precedent:=p
end
else
insertion(liste,position,p,passer);
end;
end;
end;
end;
begin
i:=0;
liste:=nil;
writeln('---------------BIENVENUE A LA SIMULATION D"UN PROGRAMME SYSTEME--------------');
writeln;
writeln;
Writeln('------------------------PROGRAMMEUR:BASSANGONEN HERVE------------------------');
writeln;
writeln;
0:writeln('--------------------------------------MENU:----------------------------------');
writeln;
writeln('TAPER 1:creation et ajout de processus en memoire');
writeln;
writeln('TAPER 2:SUPPRESSION D"UN PROCESSUS');
writeln;
writeln('TAPER 3:CALCUL DU TEMPS ECOULE AVANT LA FIN DE L"EXECUTION D"UN PROCESSUS');
writeln;
writeln('TAPER 4:AFFICHER L"ETAT DE LA LISTE D"ATTENTE DES PROCESSUS');
readln( choix );
case choix of
1:begin {creation et ajout de processus dans la liste d'attente}
fin:=false;
writeln('Preparer les donnees a entrer pour le processus');
writeln;
while not(fin) do
begin
writeln('L"identificateur du processus en cours de creation est:id',i);
id:=i;
writeln('entrer sa priorite:');
readln(prt);
writeln('entrer la duree du processus en cours:');
readln(dur);
positionadequate(liste,prt,dur,id);
i:=i+1;
writeln('Pour continuer taper 5 sinon apppuyer un chiffre du clavier numerique');
readln(brancher);
if brancher=5 then else fin:=true;
end;
if fin =true then
begin
writeln('Pour retourner au MENU taper 0 sinon sur un bouton du clavier numerique');
readln(brancher);
if brancher=0 then goto 0 else ;
end
end;
4:begin {Parcours de la liste}
if liste=nil then
begin
writeln('la liste d"attente est vide');
Writeln;
Writeln('Pour la creation d"une liste et l"ajout retour au MENU:TAPER 0');
readln(brancher);
if brancher=0 then goto 0
end
else
begin
l:=liste;
fin:=false;
writeln('les processus en attente sont les suivants:');
while not (fin) do
begin
writeln('identificateur:id',l^.info.id);
writeln('priorite du processus d"id',l^.info.id,':',l^.info.priorite);
writeln('duree du processus d"id',l^.info.id,':',l^.info.duree);
l:=l^.suivant;
fin:=l=liste;
end;
if fin=true then
begin
writeln('Pour retourner au MENU taper 0 sinon sur un chiffre du clavier numerique');
readln(brancher);
if brancher=0 then goto 0 else ;
end
end
end;
end;
end. |
Partager