Aim: - Write A Program To Implement FCFS CPU Scheduling: Algorithm

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 66

Aim: - Write a program to implement FCFS CPU scheduling

algorithm.
Explanation: - The simplest CPU scheduling algo. Is first-come, first-served (FCFS) scheduling
algorithm. With this scheme, the processes that request the CPU first is allocated the CPU
first.Ex.-

Process Burst Time

P1 4

P2 5

P3 2

Gantt Chart

P1 P2 P3

0 4 9 11

Calculation

Turn around Time= Burst Time+ (Waiting Time – Arrival Time)

Process Waiting Time Turn Around Time

P1 0-0=0 4-0=0

P2 4-0=4 9-0=9

P3 9-0=9 11-0=0

Avg. Waiting Time=(0+4+9)/3=4.33

Avg. Turn Around Time=(0+9+11)/3=8


Program

#include <stdio.h>

#include <conio.h>

#include <dos.h>

main()

_setcursortype(_NOCURSOR);

int x, y=5, z=1;

float pro, burst[100], burst2=1, gantt=0, gantt2=0, gantt3=0;

int lo, di; char menu, proc; clrscr();

sleep(2); textcolor(15);

gotoxy(43, 13); cprintf("2"); delay(100);

gotoxy(43, 13); cprintf(" ");

gotoxy(41, 13); cprintf("P"); delay(100);

gotoxy(41, 13); cprintf(" ");

gotoxy(40, 13); cprintf("U"); delay(100);

gotoxy(40, 13); cprintf(" ");

gotoxy(39, 13); cprintf("O"); delay(100);

gotoxy(39, 13); cprintf(" ");

gotoxy(38, 13); cprintf("R"); delay(100);

gotoxy(38, 13); cprintf(" ");

gotoxy(37, 13); cprintf("G"); delay(100);

gotoxy(37, 13); cprintf(" "); delay(100);

textcolor(15);
gotoxy(37, 13); cprintf("G"); delay(100);

textcolor(8);

gotoxy(37, 13); cprintf("G");

textcolor(15);

gotoxy(38, 13); cprintf("R"); delay(100);

textcolor(8);

gotoxy(38, 13); cprintf("R");

textcolor(15);

gotoxy(39, 13); cprintf("O"); delay(100);

textcolor(8);

gotoxy(39, 13); cprintf("O");

textcolor(15);

gotoxy(40, 13); cprintf("U"); delay(100);

textcolor(8);

gotoxy(40, 13); cprintf("U");

textcolor(15);

gotoxy(41, 13); cprintf("P"); delay(100);

textcolor(8);

gotoxy(41, 13); cprintf("P");

textcolor(15);

gotoxy(43, 13); cprintf("2");

delay(100);

textcolor(8);

gotoxy(43, 13); cprintf("2"); sleep(2);

clrscr(); textcolor(15);
gotoxy(28, 13); cprintf("C");

gotoxy(52, 13); cprintf("S"); delay(100);

gotoxy(28, 13); printf(" ");

gotoxy(52, 13); printf(" "); textcolor(15);

gotoxy(29, 13); cprintf("P");

gotoxy(51, 13); cprintf("M"); delay(100);

gotoxy(29, 13); printf(" ");

gotoxy(51, 13); printf(" "); textcolor(15);

gotoxy(30, 13); cprintf("U");

gotoxy(50, 13); cprintf("H"); delay(100);

gotoxy(30, 13); printf(" ");

gotoxy(50, 13); printf(" "); textcolor(15);

gotoxy(32, 13); cprintf("S");

gotoxy(49, 13); cprintf("T"); delay(100);

gotoxy(32, 13); printf(" ");

gotoxy(49, 13); printf(" "); textcolor(15);

gotoxy(33, 13); cprintf("C");

gotoxy(48, 13); cprintf("I"); delay(100);

gotoxy(33, 13); printf(" ");

gotoxy(48, 13); printf(" "); textcolor(15);

gotoxy(34, 13); cprintf("H");

gotoxy(47, 13); cprintf("R"); delay(100);

gotoxy(34, 13); printf(" ");

gotoxy(47, 13); printf(" "); textcolor(15);

gotoxy(35, 13); cprintf("E");


gotoxy(46, 13); cprintf("O"); delay(100);

gotoxy(35, 13); printf(" ");

gotoxy(46, 13); printf(" "); textcolor(15);

gotoxy(36, 13); cprintf("D");

gotoxy(45, 13); cprintf("G"); delay(100);

gotoxy(36, 13); printf(" ");

gotoxy(45, 13); printf(" "); textcolor(15);

gotoxy(37, 13); cprintf("U");

gotoxy(44, 13); cprintf("L"); delay(100);

gotoxy(37, 13); printf(" ");

gotoxy(44, 13); printf(" "); textcolor(15);

gotoxy(38, 13); cprintf("L");

gotoxy(43, 13); cprintf("A"); delay(100);

gotoxy(38, 13); printf(" ");

gotoxy(43, 13); printf(" "); textcolor(15);

gotoxy(39, 13); cprintf("I");

gotoxy(41, 13); cprintf("G"); delay(100);

gotoxy(39, 13); printf(" ");

gotoxy(41, 13); printf(" ");

gotoxy(40, 13); cprintf("N"); delay(100);

gotoxy(40, 13); printf(" "); textcolor(8);

gotoxy(40, 13); cprintf("N"); textcolor(15);

gotoxy(39, 13); cprintf("I");

gotoxy(41, 13); cprintf("G"); delay(100);

textcolor(8); gotoxy(39, 13); cprintf("I");


gotoxy(41, 13); cprintf("G"); textcolor(15);

gotoxy(38, 13); cprintf("L");

gotoxy(43, 13); cprintf("A"); delay(100);

textcolor(8); gotoxy(38, 13); cprintf("L");

gotoxy(43, 13); cprintf("A"); textcolor(15);

gotoxy(37, 13); cprintf("U");

gotoxy(44, 13); cprintf("L"); delay(100);

textcolor(8); gotoxy(37, 13); cprintf("U");

gotoxy(44, 13); cprintf("L");

textcolor(15); gotoxy(36, 13); cprintf("D");

gotoxy(45, 13); cprintf("G"); delay(100);

textcolor(8); gotoxy(36, 13); cprintf("D");

gotoxy(45, 13); cprintf("G"); textcolor(15);

gotoxy(35, 13); cprintf("E");

gotoxy(46, 13); cprintf("O"); delay(100);

textcolor(8); gotoxy(35, 13); cprintf("E");

gotoxy(46, 13); cprintf("O"); textcolor(15);

gotoxy(34, 13); cprintf("H"); gotoxy(47, 13);

cprintf("R"); delay(100); textcolor(8);

gotoxy(34, 13); cprintf("H");

gotoxy(47, 13); cprintf("R"); textcolor(15);

gotoxy(33, 13); cprintf("C");

gotoxy(48, 13); cprintf("I"); delay(100);

textcolor(8); gotoxy(33, 13); cprintf("C");

gotoxy(48, 13); cprintf("I"); textcolor(15);


gotoxy(32, 13); cprintf("S");

gotoxy(49, 13); cprintf("T"); delay(100);

textcolor(8); gotoxy(32, 13); cprintf("S");

gotoxy(49, 13); cprintf("T"); textcolor(15);

gotoxy(30, 13); cprintf("U");

gotoxy(50, 13); cprintf("H"); delay(100);

textcolor(8); gotoxy(30, 13); cprintf("U");

gotoxy(50, 13); cprintf("H"); textcolor(15);

gotoxy(29, 13); cprintf("P");

gotoxy(51, 13); cprintf("M"); delay(100);

textcolor(8); gotoxy(29, 13); cprintf("P");

gotoxy(51, 13); cprintf("M");

textcolor(15); gotoxy(28, 13); cprintf("C");

gotoxy(52, 13); cprintf("S"); delay(100);

textcolor(8); gotoxy(28, 13); cprintf("C");

gotoxy(52, 13); cprintf("S"); sleep(2);

for(x=28; x<=52; x++)

gotoxy(x, 13); printf(" ");

delay(100);

clrscr();

menu_back:

textcolor(8);
gotoxy(1, 25); cprintf("Best viewed in maximize window");

gotoxy(76, 1); cprintf("FCFS");

gotoxy(1, 1); cprintf("ÚÄÄÄÄÄÄÄ¿");

gotoxy(1, 2); cprintf("³ nter ³");

gotoxy(1, 3); cprintf("ÀÄÄÄÄÄÄÄÙ");

gotoxy(69, 23); cprintf("ÚÄÄÄÄÄÄÄÄÄ¿");

gotoxy(69, 24); cprintf("³ redits ³");

gotoxy(69, 25); cprintf("ÀÄÄÄÄÄÄÄÄÄÙ");

textcolor(15);

gotoxy(3, 2); cprintf("E");

gotoxy(71, 24); cprintf("C");

menu=getch();

if(menu=='E' || menu=='e')

clrscr();

for(lo=28; lo<=53; lo++)

textcolor(8);

gotoxy(lo,14);cprintf("ÛÛ");

for(lo=0, di=28; lo<=100; lo+=4, di++)

textcolor(15);
gotoxy(28,12);cprintf("initializing schedule...");

gotoxy(28,13);cprintf("%d%", lo);

gotoxy(di,14);cprintf("ÛÛ");

delay(200);

sleep(2);

goto go;

else if(menu=='C' || menu=='c')

goto credits;

else

goto menu_back;

go:

clrscr();

_setcursortype(_SOLIDCURSOR);

back:

textcolor(8);

gotoxy(16, 13); cprintf("ow many processes would you like to put? (1-9)");

textcolor(15);

gotoxy(15, 13); cprintf("H");

gotoxy(62, 13); cprintf(":");

gotoxy(64,13); cscanf("%c", &proc);

clrscr();

if(proc=='1')

pro=1;
else if(proc=='2')

pro=2;

else if(proc=='3')

pro=3;

else if(proc=='4')

pro=4;

else if(proc=='5')

pro=5;

else if(proc=='6')

pro=6;

else if(proc=='7')

pro=7;

else if(proc=='8')

pro=8;

else if(proc=='9')

pro=9;

else

goto back;

_setcursortype(_SOLIDCURSOR);

textcolor(8);

gotoxy(28, 2); cprintf("ÚÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄ¿");

gotoxy(28, 3); cprintf("³ Process ³ ³");

gotoxy(28, 4); cprintf("ÃÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄ´");

textcolor(15);

gotoxy(40, 3); cprintf("Burst Time");


for(x=1; x<=pro; x++)

textcolor(8);

gotoxy(28, y); cprintf("³ ³ ³");

gotoxy(28, y+1); cprintf("ÃÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄ´");

textcolor(15);

gotoxy(32, y); cprintf("P%d", x);

y+=2;

textcolor(8);

gotoxy(28, y-1); cprintf("ÀÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÙ");

y=5;

limits:

do{

textcolor(15);

gotoxy(44, y); cscanf("%c", &proc);

if(proc=='1')

burst[burst2]=1;

else if(proc=='2')

burst[burst2]=2;

else if(proc=='3')

burst[burst2]=3;

else if(proc=='4')

burst[burst2]=4;

else if(proc=='5')
burst[burst2]=5;

else if(proc=='6')

burst[burst2]=6;

else if(proc=='7')

burst[burst2]=7;

else if(proc=='8')

burst[burst2]=8;

else if(proc=='9')

burst[burst2]=9;

else

textcolor(8);

gotoxy(44, y); printf(" ");

goto limits; }

burst2++;

y+=2;

z++;}

while(z<=pro);

_setcursortype(_NOCURSOR);

gotoxy(1, 25); cprintf("P");

gotoxy(26,25);cprintf("...");

textcolor(8);

gotoxy(40, 3); cprintf("Burst Time");

gotoxy(2, 25); cprintf("ress any key to continue"); getch(); clrscr();

textcolor(8);
gotoxy(2, 1); cprintf("he Gantt Char");

textcolor(15);

gotoxy(1, 1); cprintf("T");

gotoxy(15, 1); cprintf("t");

textcolor(8);

gotoxy(1, 3); cprintf("Ú");

gotoxy(1, 4); cprintf("³");

gotoxy(1, 5); cprintf("À"); y=2;

for(x=1; x<=pro; x++)

textcolor(8);

gotoxy(y, 3); cprintf("ÄÄÄÄÄÄÂ");

gotoxy(y, 4); cprintf(" ³");

gotoxy(y, 5); cprintf("ÄÄÄÄÄÄÁ");

textcolor(15);

gotoxy(y+1, 4); cprintf("P%d", x);

y+=7; }

textcolor(8);

gotoxy(y-1, 3); cprintf("¿");

gotoxy(y-1, 4); cprintf("³");

gotoxy(y-1, 5); cprintf("Ù");

y=1;

burst2=1;

for(x=1; x<=pro+1; x++)

{
textcolor(15);

gotoxy(y, 6); cprintf("%g", gantt);

gantt+=burst[burst2];

burst2++;

y+=7; }

gotoxy(52, 25); cprintf("P");

gotoxy(77, 25);cprintf("...");

textcolor(8);

gotoxy(53, 25); cprintf("ress any key to continue");

getch();

clrscr();

y=5;

gotoxy(20, 2); cprintf("ÚÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿");

gotoxy(20, 3); cprintf("³ ³ Waiting Time ³ Turnaround Time ³");

gotoxy(20, 4); cprintf("ÃÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´");

for(x=1; x<=pro; x++)

textcolor(8);

gotoxy(20, y); cprintf("³ ³ ³ ³");

gotoxy(20, y+1); cprintf("ÃÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´");

textcolor(15);

gotoxy(22, y); cprintf("P%d", x);

y+=2; }

textcolor(8);

gotoxy(20, y-1); cprintf("ÀÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ");


y=5;

gantt=0;

burst2=1;

for(x=1; x<=pro; x++)

textcolor(15);

gotoxy(28, y); cprintf("%g - 0 = %g", gantt, gantt);

gantt2+=gantt;

gantt+=burst[burst2];

burst2++;

y+=2;

y=5;

burst2=1;

gantt=burst[burst2];

for(x=1; x<=pro; x++)

textcolor(15);

gotoxy(44, y); cprintf("%g - 0 = %g", gantt, gantt);

gantt3+=gantt;

burst2++;

gantt+=burst[burst2];

y+=2;

}
gotoxy(1, 25); cprintf("P");

gotoxy(26,25);cprintf("...");

textcolor(8);

gotoxy(2, 25); cprintf("ress any key to continue");

getch();

clrscr();

textcolor(8);

gotoxy(2, 1); cprintf("verage Waiting Tim");

gotoxy(2, 5); cprintf("verage Turnaround Tim");

gotoxy(1, 3); cprintf("(");

textcolor(15);

gotoxy(1, 1); cprintf("A");

gotoxy(20, 1);fv cprintf("e");

gotoxy(1, 5); cprintf("A");

gotoxy(23, 5); cprintf("e");

gotoxy(1, 3); cprintf("%g", gantt2/pro);

gotoxy(1, 7); cprintf("%g", gantt3/pro);

gotoxy(56, 25); cprintf("P");

gotoxy(77,25);cprintf("...");

textcolor(8);

gotoxy(57, 25); cprintf("Press any key to exit");

getch();

goto end;

credits:
clrscr();

textcolor(8);

gotoxy(2, 1); cprintf("Programmers:");

gotoxy(15, 1); cprintf("Gurudatta Verma");

textcolor(15);

textcolor(8);

gotoxy(57, 25); cprintf("Press any key to exit");

getch();

clrscr();

goto menu_back;

end:

clrscr();

textcolor(4);

gotoxy(37,13);cprintf("THE END!");

return 0;

Input: -

Process Burst Time

P1 4

P2 5

P3 2

Output:-

Gantt Chart

P1 P2 P3

0 4 9 11

Aim: - Write a program to implement SJF CPU scheduling


algorithm.
Explanation: - The algo. Associates with each process the length of the letter’s next CPU burst.
When the CPU is available, it is assigned to the process that has the smallest next CPU burst.

Process Burst Time

P1 4

P2 5

P3 2

Gantt Chart

P1 P2 P3

0 2 6 11

Calculation

Turn around Time= Burst Time+ (Waiting Time – Arrival Time)

Process Waiting Time Turn Around Time

P1 2-0=2 6-0=6

P2 6-0=6 11-0=11

P3 0-0=0 2-0=2

Avg. Waiting Time=(2+6+0)/3=4.33

Avg. Turn Around Time=(6+2+11)/3=6.33

Program

#include <stdio.h>
#include <conio.h>

#include <dos.h>

main()

_setcursortype(_NOCURSOR);

clrscr();

int min, nodup, nodup2[10]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, noduparr=0;

int z=1, y=5, y2=3, x, xg=2, xgv=7;

int ganttval=0, wtnttchart[100], wtnttchart2[100];

float processno, burtym[100], burtymarr=1, wtadd=0, ttadd=0;

int lo, di;

char menu, proc;

sleep(2);

textcolor(15);

gotoxy(44,13);cprintf("X");

delay(100);

textcolor(0);

gotoxy(44,13);cprintf(" ");

textcolor(15);

gotoxy(42,13);cprintf("O");

delay(100);

textcolor(0);

gotoxy(42,13);cprintf(" ");

textcolor(15);

gotoxy(41,13);cprintf("C");
delay(100);

textcolor(0);

gotoxy(41,13);cprintf(" ");

textcolor(15);

gotoxy(40,13);cprintf("I");

delay(100);

textcolor(0);

gotoxy(40,13);cprintf(" ");

textcolor(15);

gotoxy(39,13);cprintf("R");

delay(100);

textcolor(0);

gotoxy(39,13);cprintf(" ");

textcolor(15);

gotoxy(38,13);cprintf("N");

delay(100);

textcolor(0);

gotoxy(38,13);cprintf(" ");

textcolor(15);

gotoxy(37,13);cprintf("E");

delay(100);

textcolor(0);

gotoxy(37,13);cprintf(" ");

delay(100);

textcolor(15);
gotoxy(37,13);cprintf("E");

delay(100);

textcolor(8);

gotoxy(37,13);cprintf("E");

textcolor(15);

gotoxy(38,13);cprintf("N");

delay(100);

textcolor(8);

gotoxy(38,13);cprintf("N");

textcolor(15);

gotoxy(39,13);cprintf("R");

delay(100);

textcolor(8);

gotoxy(39,13);cprintf("R");

textcolor(15);

gotoxy(40,13);cprintf("I");

delay(100);

textcolor(8);

gotoxy(40,13);cprintf("I");

textcolor(15);

gotoxy(41,13);cprintf("C");

delay(100);

textcolor(8);

gotoxy(41,13);cprintf("C");

textcolor(15);
gotoxy(42,13);cprintf("O");

delay(100);

textcolor(8);

gotoxy(42,13);cprintf("O");

textcolor(15);

gotoxy(44,13);cprintf("X");

delay(100);

textcolor(8);

gotoxy(44,13);cprintf("X");

sleep(2);

clrscr();

textcolor(15);

gotoxy(28, 13); cprintf("C");

gotoxy(52, 13); cprintf("S");

delay(100);

gotoxy(28, 13); printf(" ");

gotoxy(52, 13); printf(" ");

textcolor(15);

gotoxy(29, 13); cprintf("P");

gotoxy(51, 13); cprintf("M");

delay(100);

gotoxy(29, 13); printf(" ");

gotoxy(51, 13); printf(" ");

textcolor(15);

gotoxy(30, 13); cprintf("U");


gotoxy(50, 13); cprintf("H");

delay(100);

gotoxy(30, 13); printf(" ");

gotoxy(50, 13); printf(" ");

textcolor(15);

gotoxy(32, 13); cprintf("S");

gotoxy(49, 13); cprintf("T");

delay(100);

gotoxy(32, 13); printf(" ");

gotoxy(49, 13); printf(" ");

textcolor(15);

gotoxy(33, 13); cprintf("C");

gotoxy(48, 13); cprintf("I");

delay(100);

gotoxy(33, 13); printf(" ");

gotoxy(48, 13); printf(" ");

textcolor(15);

gotoxy(34, 13); cprintf("H");

gotoxy(47, 13); cprintf("R");

delay(100);

gotoxy(34, 13); printf(" ");

gotoxy(47, 13); printf(" ");

textcolor(15);

gotoxy(35, 13); cprintf("E");

gotoxy(46, 13); cprintf("O");


delay(100);

gotoxy(35, 13); printf(" ");

gotoxy(46, 13); printf(" ");

textcolor(15);

gotoxy(36, 13); cprintf("D");

gotoxy(45, 13); cprintf("G");

delay(100);

gotoxy(36, 13); printf(" ");

gotoxy(45, 13); printf(" ");

textcolor(15);

gotoxy(37, 13); cprintf("U");

gotoxy(44, 13); cprintf("L");

delay(100);

gotoxy(37, 13); printf(" ");

gotoxy(44, 13); printf(" ");

textcolor(15);

gotoxy(38, 13); cprintf("L");

gotoxy(43, 13); cprintf("A");

delay(100);

gotoxy(38, 13); printf(" ");

gotoxy(43, 13); printf(" ");

textcolor(15);

gotoxy(39, 13); cprintf("I");

gotoxy(41, 13); cprintf("G");

delay(100);
gotoxy(39, 13); printf(" ");

gotoxy(41, 13); printf(" ");

gotoxy(40, 13); cprintf("N");

delay(100);

gotoxy(40, 13); printf(" ");

textcolor(8);

gotoxy(40, 13); cprintf("N");

textcolor(15);

gotoxy(39, 13); cprintf("I");

gotoxy(41, 13); cprintf("G");

delay(100);

textcolor(8);

gotoxy(39, 13); cprintf("I");

gotoxy(41, 13); cprintf("G");

textcolor(15);

gotoxy(38, 13); cprintf("L");

gotoxy(43, 13); cprintf("A");

delay(100);

textcolor(8);

gotoxy(38, 13); cprintf("L");

gotoxy(43, 13); cprintf("A");

textcolor(15);

gotoxy(37, 13); cprintf("U");

gotoxy(44, 13); cprintf("L");

delay(100);
textcolor(8);

gotoxy(37, 13); cprintf("U");

gotoxy(44, 13); cprintf("L");

textcolor(15);

gotoxy(36, 13); cprintf("D");

gotoxy(45, 13); cprintf("G");

delay(100);

textcolor(8);

gotoxy(36, 13); cprintf("D");

gotoxy(45, 13); cprintf("G");

textcolor(15);

gotoxy(35, 13); cprintf("E");

gotoxy(46, 13); cprintf("O");

delay(100);

textcolor(8);

gotoxy(35, 13); cprintf("E");

gotoxy(46, 13); cprintf("O");

textcolor(15);

gotoxy(34, 13); cprintf("H");

gotoxy(47, 13); cprintf("R");

delay(100);

textcolor(8);

gotoxy(34, 13); cprintf("H");

gotoxy(47, 13); cprintf("R");

textcolor(15);
gotoxy(33, 13); cprintf("C");

gotoxy(48, 13); cprintf("I");

delay(100);

textcolor(8);

gotoxy(33, 13); cprintf("C");

gotoxy(48, 13); cprintf("I");

textcolor(15);

gotoxy(32, 13); cprintf("S");

gotoxy(49, 13); cprintf("T");

delay(100);

textcolor(8);

gotoxy(32, 13); cprintf("S");

gotoxy(49, 13); cprintf("T");

textcolor(15);

gotoxy(30, 13); cprintf("U");

gotoxy(50, 13); cprintf("H");

delay(100);

textcolor(8);

gotoxy(30, 13); cprintf("U");

gotoxy(50, 13); cprintf("H");

textcolor(15);

gotoxy(29, 13); cprintf("P");

gotoxy(51, 13); cprintf("M");

delay(100);

textcolor(8);
gotoxy(29, 13); cprintf("P");

gotoxy(51, 13); cprintf("M");

textcolor(15);

gotoxy(28, 13); cprintf("C");

gotoxy(52, 13); cprintf("S");

delay(100);

textcolor(8);

gotoxy(28, 13); cprintf("C");

gotoxy(52, 13); cprintf("S");

sleep(2);

for(x=28; x<=52; x++)

gotoxy(x, 13); printf(" ");

delay(100);

clrscr();

menu_back:

textcolor(8);

gotoxy(1, 25); cprintf("Best viewed in maximize window");

gotoxy(77, 1); cprintf("SJF");

gotoxy(1, 1); cprintf("ÚÄÄÄÄÄÄÄ¿");

gotoxy(1, 2); cprintf("³ nter ³");

gotoxy(1, 3); cprintf("ÀÄÄÄÄÄÄÄÙ");


gotoxy(69, 23); cprintf("ÚÄÄÄÄÄÄÄÄÄ¿");

gotoxy(69, 24); cprintf("³ redits ³");

gotoxy(69, 25); cprintf("ÀÄÄÄÄÄÄÄÄÄÙ");

textcolor(15);

gotoxy(3, 2); cprintf("E");

gotoxy(71, 24); cprintf("C");

menu=getch();

if(menu=='E' || menu=='e')

clrscr();

for(lo=28; lo<=53; lo++)

textcolor(8);

gotoxy(lo,14);cprintf("ÛÛ");

for(lo=0, di=28; lo<=100; lo+=4, di++)

textcolor(15);

gotoxy(28,12);cprintf("initializing schedule...");

gotoxy(28,13);cprintf("%d%", lo);

gotoxy(di,14);cprintf("ÛÛ");

delay(200);

sleep(2);

goto go;
}

else if(menu=='C' || menu=='c')

goto credits;

else

goto menu_back;

go:

clrscr();

_setcursortype(_SOLIDCURSOR);

back:

textcolor(8);

gotoxy(16, 13); cprintf("ow many processes would you like to put? (1-9)");

textcolor(15);

gotoxy(15, 13); cprintf("H");

gotoxy(62, 13); cprintf(":");

gotoxy(64,13); cscanf("%c", &proc);

clrscr();

if(proc=='1')

processno=1;

else if(proc=='2')

processno=2;

else if(proc=='3')

processno=3;

else if(proc=='4')

processno=4;
else if(proc=='5')

processno=5;

else if(proc=='6')

processno=6;

else if(proc=='7')

processno=7;

else if(proc=='8')

processno=8;

else if(proc=='9')

processno=9;

else

goto back;

_setcursortype(_SOLIDCURSOR);

textcolor(8);

gotoxy(28, 2); cprintf("ÚÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄ¿");

gotoxy(28, 3); cprintf("³ Process ³ ³");

gotoxy(28, 4); cprintf("ÃÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄ´");

textcolor(15);

gotoxy(40, 3); cprintf("Burst Time");

for(x=1; x<=processno; x++)

textcolor(8);

gotoxy(28, y); cprintf("³ ³ ³");

gotoxy(28, y+1); cprintf("ÃÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄ´");

textcolor(15);
gotoxy(32, y); cprintf("P%d", x);

y+=2;

textcolor(8);

gotoxy(28, y-1); cprintf("ÀÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÙ");

y=5;

limits:

do

textcolor(15);

gotoxy(44, y); cscanf("%c", &proc);

if(proc=='1')

burtym[burtymarr]=1;

else if(proc=='2')

burtym[burtymarr]=2;

else if(proc=='3')

burtym[burtymarr]=3;

else if(proc=='4')

burtym[burtymarr]=4;

else if(proc=='5')

burtym[burtymarr]=5;

else if(proc=='6')

burtym[burtymarr]=6;
else if(proc=='7')

burtym[burtymarr]=7;

else if(proc=='8')

burtym[burtymarr]=8;

else if(proc=='9')

burtym[burtymarr]=9;

else

gotoxy(44, y); printf(" ");

goto limits;

burtymarr++;

y+=2;

z++;

while(z<=processno);

_setcursortype(_NOCURSOR);

gotoxy(1, 25); cprintf("P");

gotoxy(26,25);cprintf("...");

textcolor(8);

gotoxy(40, 3); cprintf("Burst Time");

gotoxy(2, 25); cprintf("ress any key to continue");

getch();

clrscr();
y=4;

for(x=1; x<=processno; x++)

min=10000;

for(burtymarr=1; burtymarr<=processno; burtymarr++)

if(min>burtym[burtymarr] && burtymarr!=nodup2[0] && burtymarr!=nodup2[1]

&& burtymarr!=nodup2[2] && burtymarr!=nodup2[3] && burtymarr!=nodup2[4]

&& burtymarr!=nodup2[5] && burtymarr!=nodup2[6] && burtymarr!=nodup2[7]

&& burtymarr!=nodup2[8] && burtymarr!=nodup2[9])

nodup=burtymarr;

min=burtym[burtymarr];

textcolor(8);

gotoxy(1, 3); cprintf("Ú");

gotoxy(1, 4); cprintf("³");

gotoxy(1, 5); cprintf("À");

gotoxy(xg, 3); cprintf("ÄÄÄÄÄÄÂ");

gotoxy(xg, 4); cprintf(" ³");

gotoxy(xg, 5); cprintf("ÄÄÄÄÄÄÁ");

textcolor(15);

gotoxy(y2, y); cprintf("P%g", burtymarr);

}
wtnttchart2[nodup]=ganttval;

wtadd+=wtnttchart2[nodup];

ganttval+=min;

textcolor(15);

gotoxy(1, 6); cprintf("0");

gotoxy(xgv, 6); cprintf("%d", ganttval);

y2+=7;

xg+=7;

xgv+=7;

nodup2[noduparr]=nodup;

wtnttchart[nodup]=ganttval;

ttadd+=wtnttchart[nodup];

noduparr++;

textcolor(8);

gotoxy(xg-1, 3); cprintf("¿");

gotoxy(xg-1, 4); cprintf("³");

gotoxy(xg-1, 5); cprintf("Ù");

textcolor(8);

gotoxy(2, 1); cprintf("he Gantt Char");

textcolor(15);

gotoxy(1, 1); cprintf("T");

gotoxy(15, 1); cprintf("t");

gotoxy(52, 25); cprintf("P");

gotoxy(77, 25);cprintf("...");
textcolor(8);

gotoxy(53, 25); cprintf("ress any key to continue");

getch();

clrscr();

y=5;

gotoxy(20, 2); cprintf("ÚÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿");

gotoxy(20, 3); cprintf("³ ³ Waiting Time ³ Turnaround Time ³");

gotoxy(20, 4); cprintf("ÃÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´");

for(x=1; x<=processno; x++)

textcolor(8);

gotoxy(20, y); cprintf("³ ³ ³ ³");

gotoxy(20, y+1); cprintf("ÃÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´");

textcolor(15);

gotoxy(22, y); cprintf("P%d", x);

y+=2;

textcolor(8);

gotoxy(20, y-1); cprintf("ÀÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ;

textcolor(15);

y=5;

for(x=1; x<=processno; x++)

gotoxy(28, y); cprintf("%d - 0 = %d", wtnttchart2[x], wtnttchart2[x]);

y+=2;
}

y=5;

for(x=1; x<=processno; x++)

gotoxy(44, y); cprintf("%d - 0 = %d", wtnttchart[x], wtnttchart[x]);

y+=2;

gotoxy(1, 25); cprintf("P");

gotoxy(26,25);cprintf("...");

textcolor(8);

gotoxy(2, 25); cprintf("ress any key to continue");

getch();

clrscr();

textcolor(8);

gotoxy(2, 1); cprintf("verage Waiting Tim");

gotoxy(2, 5); cprintf("verage Turnaround Tim");

gotoxy(1, 3); cprintf("(");

textcolor(15);

gotoxy(1, 1); cprintf("A");

gotoxy(20, 1); cprintf("e");

gotoxy(1, 5); cprintf("A");

gotoxy(23, 5); cprintf("e");

gotoxy(1, 3); cprintf("%g", wtadd/(processno));

gotoxy(1, 7); cprintf("%g", ttadd/(processno));

gotoxy(56, 25); cprintf("P");


gotoxy(77,25);cprintf("...");

textcolor(8);

gotoxy(57, 25); cprintf("ress any key to exit");

getch();

goto end;

credits:

clrscr();

textcolor(8);

gotoxy(2, 1); cprintf("Programmer:");

gotoxy(14, 1); cprintf("Gurudatta Verma");

gotoxy(2, 25); cprintf("Press any key to exit");

textcolor(15);

getch();

clrscr();

goto menu_back

end:

clrscr();

textcolor(4);

gotoxy(37,13);cprintf("THE END!");

return 0;

Input: -
Ex.-

Process Burst Time

P1 4

P2 5

P3 2

Output:

Gantt Chart

P1 P2 P3

0 2 6 11
Aim: - Write a program to implement Round-Robin (RR) CPU

scheduling lgorithm.

Explanation: -The RR CPU Scheduling algorithm is designed especially for time sharing systems.
It is similar to FCFS scheduling, but preemption is added to switch between processes. A small
unit of time called time quantum. Ex.-

Process Burst Time

P1 4

P2 5

Gantt Chart

Suppose time quantum=2

P1 P2 P1 P2 P2

0 2 4 6 8 9

Calculation

Turn around Time= Burst Time+ (Waiting Time – Arrival Time)

Process Waiting Time Turn Around Time

P1 (0-2)+(2-6)=6 6-0=6

P2 (2-4)+(4-8)+(8-9)=7 7-0=7

Avg. Waiting Time=(6+7)/2=6.5

Avg. Turn Around Time=(6+7)/2=6.5

Program: -
#include<stdio.h>

#include<conio.h>

#include<dos.h>

#include<graphics.h>

#define N 100

struct processors //PROCESS ATTRIBUTES//

float burst;

float arrival;

int priority;

int num;

}p[20],temp;

struct ssss

int no;

int xx;

float arr;

float burst;

float ww;

int pri;

float wait;

}process[N];

void main()

{
void roundrobin(int);

int i,j,n;float left,right,top,bottom;

/* select a driver and mode that supports */

/* multiple background colors. */

int gdriver = EGA, gmode = EGAHI, errorcode;

int bkcol, maxcolor, x, y;

char msg[80];

/* initialize graphics and local variables */

initgraph(&gdriver, &gmode, "C:\\TC\\BGI");

/* read result of initialization */

errorcode = graphresult();

if (errorcode != grOk) /* an error occurred */

printf("Graphics error: %s\n", grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

exit(1); /* terminate with an error code */

cleardevice();//Gets the input from the user//

printf("ENTER THE NUMBER OF PROCESSES:\t");

scanf("%d",&n);

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

gotoxy(22,2);

printf("PROCESS:%d\n",i+1);

printf("BURST TIME :\t");

scanf("%f",&p[i].burst);

printf("ARRIVAL TIME :\t");

scanf("%f",&p[i].arrival);

printf("PRIORITY :\t");

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

p[i].num = i+1;

if(p[i].arrival < 0 || p[i].burst <=0 || p[i].priority > n || p[i].burst> 40)

printf("\n\nINVALID INPUT\n");

printf("PLEASE RE ENTER THE PARAMETERS FOR


PROCESS%d",i+1);

i--;

getch();

cleardevice();

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

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

if(p[i].arrival > p[j].arrival)


{

temp = p[i];

p[i] = p[j];

p[j] = temp;

cleardevice();

gotoxy(22,2);

//Selects the scheduling algorithm

printf("5.ROUND ROBIN scheduling\n");

roundrobin(n);

getch();

//ROUND ROBIN ALGORITHM

void roundrobin(int n)

int i,j,l=0,pr[30];float

tot[10]={1,1,1,1,1,1,1,1,1,1},s[10]={0,0,0,0,0,0,0,0,0,0},c=1,y=0;

float q,awt,total=0,wt[10]={0,0,0,0,0,0,0,0,0,0},g[400];

void graphics(float *,float,int,float *,int,int *,int);

cleardevice();
printf("Enter the time quantum: ");

scanf("%f",&q);

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

tot[i] = p[i].burst;

g[y++] = total;

g[y++] = 0;

g[y++] = total = total + p[0].arrival;

while(c<=n) //Keeps track of the processes that are completed

for(i=0;i<n;j++)//Performs the round robin function

if(tot[i]>0) //Checks whether the process is over or not

tot[i] = tot[i] - q; //decreases the burst time by the

//time quantum

if(tot[i]<=0) // checks whether this is the last

//round for this process

g[y++] = p[i].num;

g[y++] = total = total + tot[i] + q;

//calculates the waiting time of the proces

wt[i] = total - p[i].burst - p[i].arrival;

//checks whether a process has arrived in the mean time


if(total>=p[i+1].arrival)

i++;

else

i=0;

c++;

else

g[y++] = p[i].num;

g[y++] = total = total + q;

while(tot[i+1]<=0)//increments 'i' till it reaches an incomplete

i++; //process

if(total>=p[i+1].arrival)

i++;

else

i=0;

}
}

else

i++;

if(p[i].arrival > total) //checks for idle time

if(i<=n)

g[y++] = 0;

g[y++] = total = p[i].arrival;

else if(i==n-1 && c==n-1)

g[y++] = 0;

g[y++] = total = p[i].arrival;

g[y++] = p[i-1].num;

q=0;
for(i=0;i<n;i++) //calculates average waiting time

//printf("%d. %f\n",p[i].num,wt[i]);

q = q + wt[i];

awt = q/n;

graphics(&wt,awt,n,&g,y,&pr,l);

outtextxy(200,0,"FOR ROUND ROBIN SCHEDULING");

getch();

void graphics(float *wt,float awt,int n,float *g,int y,int *pr,int l)

int i,msg1=0,j=0,u=0;

char msg[30];

float left,right,top,bottom,awd=0,turn=0,d=0;

getch();

cleardevice();

setlinestyle(4, 1, 1);

setfillstyle(10,1);

bar3d(0,0,620,340,0,0);

line(0, 2, 618, 2);

line(2,2,2,338);

line(2,338,618,338);

line(618,338,618,2);

setlinestyle(0,1,1);
left = 0;

top = 40;

bottom = 80;

right = 15;

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

left = right;

right = *(g+i);

right = (15-j) * (right - u);

bar3d(left,top,right,bottom,0,0);

sprintf(msg,"%2.1f",*(g+i));

outtextxy(right,(82+msg1),msg);

i++;

setfillstyle(1,*(g+i));

if(right>=600)

right = 0;

top = 120;

bottom = 160;

msg1 = 82;u= *(g+i-1);

i--;

outtextxy(right,164,msg);

i++;

delay(500);
}

setcolor(CYAN+BLINK);

settextstyle(DEFAULT_FONT, HORIZ_DIR, 0);

sprintf(msg,"AVERAGE WAITING TIME : %f",awt);

outtextxy(20,30,msg);

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

d = d + p[i].burst;

awd = d/n;

turn = awd + awt;

//settextstyle(DEFAULT_FONT, HORIZ_DIR, 4);

sprintf(msg,"AVERAGE TURN AROUND TIME : %f",turn);

outtextxy(300,30,msg);

setcolor(WHITE);

sprintf(msg,"PROCESS");

outtextxy(32,210,msg);

sprintf(msg,"WAITING TIME");

outtextxy(190,210,msg);

outtextxy(340,210,"COLORS");

outtextxy(410,210,"IDLE");

setfillstyle(1,0);

bar3d(455,206,515,216,0,0);

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

{
sprintf(msg,"%d.",p[i].num);

outtextxy(48,226+(i*17),msg);

sprintf(msg,"%f",*(wt+i));

outtextxy(208,226+(i*17),msg);

if(i==6)

break;

//getch();

//cleardevice();

/*for(i=7;i<n;i++)

sprintf(msg,"%d.",p[i].num);

outtextxy(48,226+((i-7)*17),msg);

sprintf(msg,"%f",*(wt+i));

outtextxy(208,226+((i-7)*17),msg);

} */

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

setfillstyle(1,p[i].num);

bar3d(330,225+(i*17),390,235+(i*17),0,0);

if(i==6)

break;

settextstyle(TRIPLEX_FONT, HORIZ_DIR,2 );

outtextxy(50,0,"GANTT CHART");
if(n>=7)

getch();

cleardevice();

settextstyle(DEFAULT_FONT,HORIZ_DIR,0);

sprintf(msg,"PROCESS");

outtextxy(32,10,msg);

sprintf(msg,"WAITING TIME");

outtextxy(190,10,msg);

outtextxy(340,10,"COLORS");

outtextxy(410,10,"IDLE");

setfillstyle(1,0);

bar3d(455,6,515,16,0,0);

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

sprintf(msg,"%d.",p[i].num);

outtextxy(48,26+((i-7)*17),msg);

sprintf(msg,"%f",*(wt+i));

outtextxy(208,26+((i-7)*17),msg);

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

setfillstyle(1,p[i].num);

bar3d(330,25+((i-7)*17),390,35+((i-7)*17),0,0);

}
}

getch();

Input: -

Process Burst Time

P1 4

P2 5

Output: -

Process Waiting Time Turn Around Time

P1 (0-2)+(2-6)=6 6-0=6

P2 (2-4)+(4-8)+(8-9)=7 7-0=7

Aim: - Write a program to implement Priority CPU scheduling


algorithm.

Explanation: - - The algorithm Associates with each process the length of the letter’s next CPU
burst. When the CPU is available, it is assigned to the process that has the highest priority.

Program:-

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

struct process

int process_no;

int burst_time;

int priority;

int flag;

struct process *next;

struct process *back;

}typedef pr;

pr* create();

pr* copy_list(pr *);

void display(pr *);

void sort(pr *);

void priority_scheduling( pr *);

int i,no,choise,time_quantum,temp=0;
void main()

pr *head,*head1,*head2,*head3,*head4,*sjf;

pr *p,*q;

head=create();

head1=copy_list(head);

head2=copy_list(head);

head3=copy_list(head);

head4=copy_list(head);

clrscr();

printf("\n\t\t\tProcess \t Burst Time");

for(q=head1;q!=NULL;q=q->next)

printf("\n \t p%d\t %d",q->process_no,q->burst_time);

display(head1);

priority_scheduling(head3);

//function to store info about process in ready queue

pr * create()

pr *head,*prev;

printf("Enter Total No Of process");

scanf("%d",&no);

p->process_no=1;
p=(pr *)malloc(sizeof(pr));

printf("\n \t\tBurst Time For P1");

scanf("%d",&p->burst_time);

p->process_no=1;

p->flag=1;

head->prev=p;

for(i=1;i<no;i++)

p=(pr *)malloc(sizeof(pr));

printf("\n\Burdt btime for P=%d",i+1);

scanf("%d",p->burst_time);

p->process_no=i+1;

p->flag=1;

prev->next=p;

prev=p;

p->next=NULL;

return head;

//Function to display gantt chart

void display(pr *head1)

char s1[2],s3[2];

int gd=DETECT,gm,x=10;
float num=0;

initgraph(&gm,&gd,"c:\\tc\\bgi");

printf("\n\tProcess\tBurst Time");

for(q=hend1;q!=NULL;q=q->next)

settextstyle(1,0,2);

outtextxy(10,250,"GANTT CHART");

outtextxy(10,360,"0");

outtextxy(140,4,"Priority CPU Scheduling");

temp=0;

for(q=head1;q!=NULL;q=q->next)

rectangle(x,300,x+50,q->burst_time,350);

outtextxy(x+20,320,"P");

itoa(q->process_no,s1,10);

outtextxy(x+35,320,s1);

x=x+50+q->burst_time;

temp+=q->burst_time;

itoa(temp,s3,10);

outtextxy(x+10,500,s3);

if(q->next!=NULL)

sum+=temp;

printf("Avg,. Waiting time=%f",sum);

getch();
closegratph();

//function to implement priority scheduling

void priority_scheduling(pr *head)

for(q=head;q!=NULL;q=q->next)

printf("Enter Priority 4 process P%d",q->process_no);

scanf("%d",&q->priority);

for(p=head;p->next!NULL;p=p->next)

for(q=p->next;q!=NULL;q=q=->next)

if(p->priority>q->priority)

temp=p->burst_time;

p->bursttime=q->burst_time;

q->burst_time=temp;

temp=p->process_no;

p->process_no=q->process_no;

q->process_no=temp;

}
display(head);

//function 2 copy Link list

pr *copy_list(pr *first)

pr *head1,*r,*prev;

r->burst_time=first->burst_time;

r->process_no=q->burst_time;

r->flag=1;

prev->next=r;

for(q=first->next;q!=NULL;q=q->next)

r=(pr *)malloc(sizeof(pr));

r->burst_time=q->burst_time;

r->process_no=q->process_no;

r->flag=1;

prev->next=r;

prev=r;

r->next=NULL;

return head1;

}
Input: -

Process Burst time


P1 24
P2 3
P3 3
Output: -

Process Burst time


P1 24
P2 3
P3 3

AVERAGE WAITING TIME: 3.00

GANTT CHART

P3 P2 P1
0 3 6 30

Aim: Write a program Page replacement algorithm for FIFO


Program

void main()

   int x;

  // freopen(“in.cpp”,”r”,stdin);

  while(1)

 {

     clrscr();

      printf(“\n\n\t-----MENU----“);

      printf(“\n\t1. Input”);

      printf(“\n\t2. FIFO Algorithm”);

      printf(“\n\t3. LRU (Least Recently Used) Algorithm”);

      switch(x)

   #include<stdlib.h>

   #include<stdio.h>

   #include<conio.h>

   #define max 100

   #define min 10

   int ref[max],count,frame[min],n;

      

   void input()

   {

        int i, temp;


        clrscr();

        count=0;

        printf(“\n\n\tEnter the number of page frames:  “);

        scanf(“%d”,&n);

        printf(“\n\n\tEnter the refernce string (-1 for end):  “); 

       scanf(“%d”,&temp);

       while(temp!=-1)

       {

           ref[count++]=temp;

           scanf(“%”,&temp);

        }

    }

  void  FIFO()

 {

      int i,j.fault=0;

      clrscr();

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

      frame[i]=-1;

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

       {

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

          if(frame[j]==ref[i])

          break;
          if(j==n)

          frame[fault%n]=ref[i],fault++;

          printf(“\n\nAfter inserting %d the frame status is: “,ref[i]);

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

          printf(“%d”,frame[j]);

          getch();

        }

    printf(“\n\n\tEnd to inserting the reference string.”);

    printf(“\n\n\tTotal page fault is %d.”,fault);

    printf(“\n\n\tPress any key to continue…”);

    getch();

void LRU()

   int i,j,k,stack[min],top=0,fault=0;

   clrscr();

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

    {

       if(top<n)

       stack[top++]=ref[i],fault++;

       else

       {

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

         if(stack[j]==ref[i])
         break;

         if(j<n)

         {

            for(k=j;k<n-1;k++)

            stack[k]=stack[k+1];

            stack[k]=ref[i];

          }

         else

         {

            for(k=0;k<n-1;k++)

            stack[k]=stack[k+1];

            stack[k]=ref[i];

            fault++;

          }

   }  printf(“\n\nAfter inserting %d the stack status is: “,ref[i]);

   for(j=0;j<top;j++)

    printf(“%d”, stack[j]);

    getch();

    }//for i

printf(“\n\n\tEnd to inserting the reference string.”);

printf(“\n\n\tTotal page fault is %d.”,fault);

printf(\n\n\tPress any key to continue.”);

getch();

AIM: Write a program for Page replacement algo for LRU.


Program

#include<stdlib.h>

#include<stdio.h>

#include<conio.h>

 int ref[max],count,frame[min],n;

 void input()

int i,temp;

clrscr();

count=0;

printf(\n\n\tEnter the number of page frames:”);

scanf(“%d”,&n);

printf(\n\n\tEnter the reference string(-1 for end);”);

scanf(“%d”,&temp(;

while(temp!=-1)

ref[count++]=temp;

scanf(“%d,”temp);

void main()

intx;

//freopen(in.cpp”,”r”,stdin);
while(1)

clrscr();

printf(\n\n\t-----MENU-----“);

printf(“\n\t4.LRU(least recently used) Algorithm”);

switch(x)

case2:

FIFO();

break;

case4:

LRU();

break;

case0;

exit(0);

You might also like