SCHEDULING ALGORITHMS - FIFO
SHORTEST JOB FIRST SCHEDULING
SEGMENTATION PRIORITY SCHEDULING
ROUND ROBIN SCHEDULING
DEKKER ‘S ALGORITHM
READER – WRITER PROBLEM
Memory Management
MEMORY ALLOCATION
MEMORY ALLOCATION USING PAGING
Previous Next
#include
#include “conio.h”
struct pstruct
{
int fno;
int pbit;
}ptable[10];
int pmsize,lmsize,psize,frame,page,ftable[20],frameno;
void info()
{
printf("\t\tMEMORY ALLOCATION USING PAGING\n");
printf("\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
printf("\n\nEnter the Size of Physical memory--> ");
scanf("%d",&pmsize);
printf("\n\nEnter the size of Logical memory--> ");
scanf("%d",&lmsize);
printf("\n\nEnter the partition size--> ");
scanf("%d",&psize);
frame = (int) pmsize/psize;
page = (int) lmsize/psize;
printf("\nThe Physical memory is divided into %d no.of frames\n",frame);
printf("\nThe Logical memory is divided into %d no.of pages",page);
}
void assign()
{
int i;
for (i=0;i
ptable[i].fno = -1;
ptable[i].pbit= -1;
}
for(i=0; i ftable[i] = 32555;
for (i=0;i
printf("\n\nEnter the Frame number where page %d must be placed: ",i);
scanf("%d",&frameno);
ftable[frameno] = i;
if(ptable[i].pbit == -1)
{
ptable[i].fno = frameno;
ptable[i].pbit = 1;
}
}
getch();
// clrscr();
printf("\t\tPAGE TABLE\n");
printf("\t\t~~~~~~~~~~\n");
printf("PageAddress FrameNo PresenceBit\n\n");
for (i=0;i
/* printf("\n\n\n\tFRAME TABLE\n\n");
printf("FrameAddress PageNo\n\n");
for(i=0;i printf("%d\t\t%d\n",i,ftable[i]); */
}
void cphyaddr()
{
int laddr,paddr,disp,phyaddr,baddr;
getch();
// clrscr();
printf("\n\n\n\tProcess to create the Physical Address\n\n");
printf("\nEnter the Base Address: ");
scanf("%d",&baddr);
printf("\nEnter the Logical Address: ");
scanf("%d",&laddr);
paddr = laddr / psize;
disp = laddr % psize;
if(ptable[paddr].pbit == 1 )
phyaddr = baddr + (ptable[paddr].fno*psize) + disp;
printf("\nThe Physical Address where the instruction present: %d",phyaddr);
}
void main()
{
clrscr();
info();
assign();
cphyaddr();
getch();
}
MEMORY ALLOCATION
Memory Management
Output RW
READER – WRITER PROBLEM
DEKKER ‘S ALGORITHM
ROUND ROBIN SCHEDULING
SEGMENTATION
PRIORITY SCHEDULING
SHORTEST JOB FIRST SCHEDULING
SCHEDULING ALGORITHMS - FIFO
Previous Next
#include”stdio.h”
#include”conio.h”
int i,n,p,bs[10],pro[10],mbs[10],blkno[10];
void getdata();
void ff();
void bf();
void wf();
void main()
{
int ch;
getdata();
clrscr();
do
{
clrscr();
//gotoxy(20,3);
printf("\t\tMEMORY MANAGEMENT\n");
printf("\t\t~~~~~~~~~~~~~~~~~\n\n");
printf("1.FirstFit\n2.BestFit\n3.WorstFit\nEnter your Choice: ");
scanf("%d",&ch);
getch();
clrscr();
switch (ch)
{
case 1: ff(); break;
case 2: bf(); break;
case 3: wf(); break;
}
getch();
}while(ch<4);>");;
scanf("%d",&n);
printf("\nEnter the block size of each partition\n");
for(i=1; i<=n; i++) { printf("\nEnter the Size of Block-%d : ",i); scanf("%d",&bs[i]); blkno[i] =i; } getch(); clrscr(); //gotoxy(25,5); printf("\t\tMEMORY ALLOCATION TECHNIQUES\n"); printf("\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); //gotoxy(20,7); printf("\tPROCESS INFORMATION\t"); printf("\nTotal Number of process--> ");
scanf("%d",&p);
printf("\nEnter the Size of each Process\n");
for(i=1;i<=n;i++) { printf("\nEnter the size of process-%d : ",i); scanf("%d",&pro[i]); } getch(); clrscr(); } void ff() { int flag,sum=0,j; //gotoxy(20,3); printf("\t\tFIRST FIT MEMORY ALLOCATION\n"); printf("\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"); for (i=1; i<=n; i++) mbs[i] = bs[i]; printf("Pid SizeNeeded BlockSize BlockNo AllocatedSize RemainingSize \n\n"); for(i=1;i<=n;i++) { flag = 0; for(j=1;j<=n;j++) { if(mbs[j] >= pro[i] )
{
printf("%d\t %d\t%d\t\t%d\t\t%d\t %d\n\n",i,pro[i],mbs[j],j,pro[i],mbs[j]-pro[i]);
mbs[j]=mbs[j]-pro[i];
flag=1;
break;
}
}
if( !flag )
printf("\nProcess-%d is waiting\n\n",i);
}
for(i=1; i<= n; i++) sum = sum+mbs[i]; printf("\nTotal Number of Hole left: %d",sum); } void bf() { int flag,sum=0,j; //gotoxy(20,3); printf("\t\tBEST FIT MEMORY ALLOCATION\n"); printf("\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"); for (i=1; i<=n; i++) mbs[i] = bs[i]; printf("Pid SizeNeeded BlockSize BlockNo AllocatedSize RemainingSize \n\n"); for(i=1;i
{
int t=mbs[i]; mbs[i] = mbs[j]; mbs[j] = t;
t=blkno[i]; blkno[i] = blkno[j]; blkno[j] = t;
}
for(i=1;i<=p;i++) { flag =0; for (j=1;j<=n;j++) { if(mbs[j] >= pro[i] )
{
printf("%d\t %d\t%d\t\t%d\t\t%d\t %d\n\n",i,pro[i],mbs[j],blkno[j],pro[i],mbs[j]-pro[i]);
mbs[j] = mbs[j] - pro[i];
sum = sum + mbs[j];
flag =1;
break;
}
}
if (!flag)
{
printf("\n Process-%d is waiting\n\n",i);
sum = sum + mbs[i];
}
}
printf("\n Total Number of Hole left: %d ",sum);
}
void wf()
{
int flag,sum=0,j;
//gotoxy(20,3);
printf("\t\tWORST FIT MEMORY ALLOCATION\n\n");
printf("\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
for (i=1; i<=n; i++) mbs[i] = bs[i]; printf("Pid SizeNeeded BlockSize BlockNo. AlocatedSize RemaingSize\n\n"); for(i=1;i
{
printf("%d\t %d\t%d\t\t%d\t\t%d\t %d\n\n",i,pro[i],mbs[j],blkno[j],pro[i],mbs[j]-pro[i]);
mbs[j] = mbs[j] - pro[i];
sum = sum + mbs[j];
flag =1;
break;
}
}
if (!flag)
{
printf("\n Process-%d is waiting\n\n",i);
sum = sum + mbs[i];
}
}
printf("\n Total Number of Hole left: %d ",sum);
}
OUTPUT
Previous Next
#include”stdio.h”
int main()
{
typedef int semaphore;
semaphore sread=0,swrite=0;
int ch,r=0;
clrscr();
printf("\t\t\tREADER - WRITER PROBLEM\n");
printf("\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~\n");
do
{
printf("\n\t 1. READ FROM THE FILE");
printf("\n\t 2. WRITE TO THE FILE");
printf("\n\t 3. EXIT A READER");
printf("\n\t 4. EXIT A WRITER");
printf("\n\t 5. STATUS OF THE FILE");
printf("\n\t 6. EXIT");
printf("\n\n ENTER THE CHOICE:");
scanf("%d",&ch);
switch(ch)
{
case 1:if(swrite==0)
{
sread=1;
r=r+1;
printf("\n Reader %d reads the File\n",r);
}
else
printf("\n Cannot Read while Writer Writes to the File\n");
break;
case 2:if(sread==0 && swrite==0)
{
swrite=1;
printf("\n Writer Write to the File\n");
}
else
if(sread==1)
printf("\n Cannot Write While Reader Reads the File\n");
else if(swrite==1)
printf("\n Already One Writer is Writing to the File\n");
break;
case 3:if(r!=0)
{
printf("\n Reader %d Closes the File\n",r);
r=r-1;
if(r==0)
{
printf("\n Currently no Readers are using the File\n");
sread=0;
}
else if(r==1)
printf("\n Currently Only One Reader is Reading the File\n");
else
printf("\n Currently %d Readers are Reading the File\n",r);
}
break;
case 4: if(swrite==1)
{
printf("\n Writer Closes the File");
swrite=0;
}
else
printf("\n No Writer Writing to the File");
break;
case 5: if(sread==1)
{
if(r==1)
printf("\n One Reader is Reading the File");
else
printf("\n%d Readers are Reading the File",r);
}
else if(swrite==1)
printf("\n One Writer is Writing the File");
else
printf("\n File is not in Use\n");
break;
case 6: break;
}
}
while(ch!=6);
return 0;
}
#include”stdio.h”
void main()
{
int i,j,k,n,sum,wt[10],tt[10],twt,ttat;
int t[10],p[10];
float awt,atat;
clrscr();
printf("\t\t\t(b) SHORTEST JOB FIRST SCHEDULING\n ");
printf("\t\t ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("Enter number of process\n");
scanf("%d",&n);
for(i=0;i
scanf("\n %d",&t[i]);
}
for(i=0;i
{
int temp;
temp=t[i];
t[i]=t[k];
t[k]=temp;
temp=p[i];
p[i]=p[k];
p[k]=temp;
}
}
printf("\n\n SHORTEST JOB FIRST SCHEDULING ALGORITHM");
printf("\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
printf("\n PROCESS ID \t BURST TIME \t WAITING TIME \t TURNAROUND TIME \n\n");
wt[0]=0;
for(i=0;i
sum=0;
for(k=0;k {
wt[i]=sum+t[k];
sum=wt[i];
}
}
for(i=0;i
tt[i]=t[i]+wt[i];
}
for(i=0;i
printf("%5d %d %5d %5d \n\n",p[i],t[i],wt[i],tt[i]);
}
twt=0;
ttat=t[0];
for(i=1;i
twt=twt+wt[i];
ttat=ttat+tt[i];
}
awt=(float)twt/n;
atat=(float)ttat/n;
printf("\n AVERAGE WAITING TIME %4.2f",awt);
printf("\n\n AVERAGE TURN AROUND TIME %4.2f",atat);
getch();
}
}
Previous Next
#include”stdio.h”
void main()
{
int i,n,sum,wt,tat,twt,ttat;
int t[10];
float awt,atat;
clrscr();
printf("\t\t\t\tSCHEDULING ALGORITHMS\n");
printf("\t\t ~~~~~~~~~~~~~~~~~~~~~\n");
printf("\t\t\tFIRST COME FIRST SERVE\n");
printf("Enter number of process:\n");
scanf("%d",&n);
for(i=0;i
scanf("\n %d",&t[i]);
}
printf("\n\n FIRST COME FIRST SERVE SCHEDULING ALGORITHM\n ");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n");
printf("\n ProcessID \t WaitingTime \t TurnAroundTime \n\n");
printf(" 1 0 %d \n",t[0]);
sum=0;
twt=0;
ttat=t[0];
for(i=1;i
Previous Next