S.NO.

LIST OF PROGRAMS

Done on

Sign

SHORTEST REMAINING TIME FIRST (SJF-Preemptive) #include<stdio.h> struct node { int arr; int bur; int nam; }; void sort(); void sort2(); struct node list[4],temp,temp3; int name[50],n,game[50]; int main() {int i,count=0,gum=0,e,wait=0,sumarr=0,errremov; int k=0,j=0,tt=0,t=0,tus,red,ticktock; int temp2,treasure=-1,temp4; float waiting=0,thru,turn; printf("Enter Total no. of processes: "); scanf("%d",&n); e=n; for(i=0;i<n;i++) { printf("Enter process no., arrival time , burst time:"); scanf(" %d %d %d", &list[i].nam,&list[i].arr,&list[i].bur); } game[gum]=0; gum++; for(i=0;i<n;i++) { tt=tt+list[i].bur; sumarr=sumarr+list[i].arr; if(list[i].arr>t) t=list[i].arr; } temp2=list[0].bur; while(k<t) {sort(); name[j]=list[0].nam; j++; list[0].bur--; temp2=list[0].bur; //Reducing list size if(list[0].bur==0) {for(red=0;red<n-1;red++) {list[red]=list[red+1];} n--; } for(i=0;i<n;i++) {if(list[i].arr==k) { list[i].arr++;}} k++; for(i=0;i<n;i++) {if(list[i].arr==k && temp2>list[i].bur) {temp2=list[i].bur;

tus=i; count++;}} if(count>0) {wait=wait+list[tus].arr; game[gum]=wait; gum++; temp3=list[0]; list[0]=list[tus]; list[tus]=temp3; } count=0; } printf("\n Gantt Chart \n"); for(i=0;i<j;i++) {if(treasure!=name[i]) {printf("| %d ", name[i]); treasure=name[i];}} sort2(); ticktock=gum; if(list[0].nam!=treasure && list[0].bur!=0) {wait=wait+list[0].bur; game[gum]=wait; gum++; printf("| %d ",list[0].nam);} else { errremov=gum-1; temp4=t-game[errremov]; wait=wait+list[0].bur+temp4; game[gum]=wait; gum++; } for(i=1;i<n;i++) {if(list[i].bur!=0) {wait=wait+list[i].bur; game[gum]=wait; gum++; printf("| %d ",list[i].nam); }} printf("|\n"); for(i=0;i<gum;i++) {printf(" %d ",game[i]);} for(i=ticktock;i<gum-1;i++) {waiting=waiting+game[i]; } waiting=waiting-sumarr; turn=waiting+game[gum-1]; waiting=waiting/e; turn=turn/e; printf("\n Avg Waiting time =%f",waiting); printf("\n Avg turn around time = %f",turn); return 0; } void sort() {

l++) {if (list[h].l. } } }} OUTPUT Enter Enter Enter Enter Enter Enter Total no..h++) {for(l=h+1. . process no.8 Avg turn around time =13 .h<n-1.arr) {temp=list[h]..arr>list[l]. list[h]=list[l]. process no.l. list[l]=temp. for(h=0. process no. } } }} void sort2() { int h. processes:5 arrival time arrival time arrival time arrival time arrival time .bur>list[l]. .h++) {for(l=h+1. .l++) {if (list[h]..h<n-1. . process no.. list[l]=temp. burst burst burst burst burst time: time: time: time: time: 0 1 2 3 4 0 2 3 4 4 8 6 12 2 3 | 0 0 | 4 3 Gantt Chart | 4 | 0 | 1 6 9 13 | 2 19 | 31 Avg Waiting time =6. for(h=0. list[h]=list[l].bur) {temp=list[h].l<n.l<n. of process no..int h.

i++) {printf(" Enter name.j<=i.&list[i].tt=0.&list[i].twt=0. while(i<n) {if(list[i]. wt=wt+list[0]. .b.i<n. scanf(" %c %d %d".b.b. list[j]=list[j+1]. j++.wtt. }.s==1 && list[i].ready[5].b.s=0.b).Shortest Job First(Non-Preemptive)-with arrival time #include<stdio.&n). burst time").s=1. float ttt=0. of processes”). t=wt.h=0. while(wt<tt) {i=1.process.s.i--) { for(j=1.execution[5]. for(i=1. } } } tt=tt+list[0].a <= t) {execution[j]=list[i]. } for(i=n-2.temp. for(i=0.i>=1.t.b>list[j+1]. t=wt. j=1. scanf(“%d”. } else {i++. printf(“Enter no. wt=wt+list[i]. char process.n.j=0.i++) {tt=tt+list[i]. list[i].j++) { if(list[j]. int main() { int i. &list[i].b) { temp=list[j]. list[i].b. i=1. list[j+1]=temp.wt=0. } execution[0]=list[0].arrival time.i<n.h> struct node { int a. struct node list[5].a.

arrival time. of processes 4 Enter name.b.process).i<j.i++) {twt=execution[i]. } for(i=1.i++) {h=h+execution[i-1]. arrival time.i<j.wtt=h-execution[i]. burst Enter name.} } } for(i=1.twt). } OUTPUT Enter no.i<j.25 time time time time 1 2 3 4 0 2 3 4 5 6 12 2 . printf("\n Avg turnaround time = %f". arrival time. burst Enter name.ttt). twt=twt/n. } for(i=0.a. } ttt=(twt+tt)/n.i++) {printf(" %c ". burst 1 4 2 3 Avg Wait time = 4 Avg turnaround time = 10. arrival time. burst Enter name.wtt+twt. execution[i]. printf("\n Avg Wait time = %f". execution[i].

a[10].i<n. tr=tr+h.75 .tr=0. } }} for(i=0.j++) {if(a[i]>a[j]) {temp=a[i]. scanf("%d". } for(i=0.h=0.float wt=0.i<n. a[j]=temp. scanf("%d".&n).j<n. of processes 4 Enter burst time 5 Enter burst time 6 Enter burst time 12 Enter burst time 2 2 5 6 12 Avg. printf("Avg turnaround time %f".j.i<n.n. for(i=0.&a[i]). a[i]=a[j].i++) {printf("Enter burst time").h> int main() {int i.5 Avg turnaround time 11.i<n-1. h=h+a[i].i++) { printf(" %d \n". waiting time 5.tr/n).wt/n). of processes").i++) {for(j=i+1.i++) {wt =wt +h. } OUTPUT : Enter the no.temp. printf("Enter no.a[i]).} printf(" Avg waiting time %f".Shortest Job First(Nonpremptive)-all arrive at same time #include<stdio. } for(i=0.

&p).time[10]. }} OUTPUT Enter the no. avg=avg+temp. thru=p/temp. temp=temp+a[i].a[10]. { printf("Enter the no.thru. turn=turn+temp.avg).First Come First Serve. printf("\nAverage Waiting time is %f".turn=0. float temp=0.&a[i]). } for(i=0. printf("\nAverage Turnaround time is %f". scanf("%d". of processes 4 Enter the burst time of process 0 Enter the burst time of process 1 Enter the burst time of process 2 Enter the burst time of process 3 Waiting time for process0 is 0 Waiting time for process1 is 8 Waiting time for process2 is 14 Waiting time for process3 is 26 Average waiting time is 12 Average Turnaround time is 19 Throughput = 0.i.i<p.i++) { printf("Enter the burst time of process %d ".h> int main() { int p. q[10]. for(i=0.temp).i). } avg=avg/p.all arrive at same time #include<stdio. of processes"). turn=turn/p.turn).i<p. avg=0.i++) {printf("Waiting time for process %d is %f \n".thru). scanf("%d".142857 8 6 12 2 .i. printf("\nThrouhput= %f".

for(i=0.i<n-1. for(i=0. process no. printf("\nAvg turnaround time = %f \n". process no. of processes"). h=h+bur[i].wt=0.&n). } for(i=0. printf("\nThroughput time = %f\n".tr=0.tr/5). } printf(" | P%d |\n". i). tr=tr+h-ar[i].&ar[i]).h> int main() { float ar[10].i++) {printf("Enter arr time of process %d". h=0. . processes:4 arrival time arrival time arrival time arrival time . .i<n. of process no.i++) {printf(" | P%d".k). printf("Enter burst time of process %d". } OUTPUT Enter Enter Enter Enter Enter Total no.h=0. scanf("%f"..k).i++) {printf("%d ".&bur[i]). h=h+bur[i]. . printf("Enter no.i). wt=wt+h-ar[i+1]. int n. k=k+bur[i]. wt/5)..i. scanf("%f"..bur[10]. printf("\nAvg waiting time = %f \n".16 . i). process no.n/h).with arrival time #include<stdio. }printf("%d ".i).k=0.i<n. scanf("%d". burst burst burst burst time: time: time: time: 1 2 3 4 0 5 2 6 3 12 4 2 | 0 1 | 5 2 Gantt Chart | 3 | 4 | 11 23 25 Avg Waiting time =6 Avg turn around time = 11 Throughput time = 0..First come first served.

thru.h=0. &p[i]).turn).i++) {printf("%d %d \n". } OUTPUT : Enter no.temp). turn=turn+temp. of processes 4 Enter burst time of process 0 : 5 Enter priority of process 0 : 3 Enter burst time of process 1 : 12 Enter priority of process 1 : 4 Enter burst time of process 2 : 3 Enter priority of process 2 : 1 Enter burst time of process 3 : 7 Enter priority of process 3 : 2 3 1 7 2 .h> int main() {int i.i++) {printf("Waiting time for process %d = %f \n".a[10]. turn=turn/n.i++) {for(j=i+1. b[j]=temp. avg=0. b[10]. for(i=0.thru).j++) {if(p[i]>p[j]) {temp=p[i]. scanf("%d". avg=avg+temp.j<n. printf("\nThrouhput = %f".i<n. thru=n/temp.i<n.j. i).b[i]. temp=b[i]. } avg=avg/n. for(i=0.i<n. of processes"). printf("Enter no. } } } for(i=0. p[i]).i. printf("\nAverage Waiting time = %f". b[i]=b[j].n. } for(i=0.avg).i<n. p[j]=temp.i++) {printf(" Enter burst time of process %d ". &b[i]). scanf("%d".all arrive at same time #include<stdio.PRIORITY Scheduling(Non-premptive). printf("\nAverage Turnaround time = %f".turn=0. printf("Enter priority of process %d". p[10].&n). float temp=0. temp=temp+b[i]. scanf("%d". p[i]=p[j].i). } temp=0.

75 Throughput = 0.148148 .5 3 12 4 Waiting Waiting Waiting Waiting time time time time for for for for process process process process 0 1 2 3 = = = = 0 3 10 15 Average Waiting time = 7 Average Turnaround time = 13.

printf("Enter no. start=start+tslice.n. tt=tt+p[i]. order[j]=p[i]. int bur.t=0. of processes"). scanf(" %c %d".i<n.last. float twt=0.i<n.last=t. p[i].bur-tslice.order[100].i++) {printf("%c". j++.i<j.bur).tt=0. } for(i=0. &p[i].k.i+1). } else {i++.name.} .&p[i].k+start-p[i].last.bur=p[i].&n).name).bur<0) {start=start+p[i].bur. for(i=0.k+twt. } while(start<tt) { i=0.k=p[i].k=0. }. i++.Round Robin CPU scheduling #include<stdio.bur. printf("Average waiting time is %f". p[i].i++) {printf("Enter name. } p[i].} twt=(twt)/n. int main() {int i.i++) {twt=p[i]. return 0.start=0.twt).&tslice).bur!=0) {p[i]. burst time of process %d ". p[i].order[i].last=start.h> struct node { char name. scanf("%d". scanf("%d". }}} for(i=0. printf("Enter time slice"). p[i]. struct node p[10].j=0. while(i<n) { if(p[i].bur=0. if(p[i].tslice.

burst time of process 4 : 4 2 1 2 3 4 1 2 3 3 Average waiting time is 11.5 . of processes Enter time slice 4 1 : 1 5 2 : 2 6 4 Enter name. burst time of process 3 : 3 12 Enter name.Output Enter no. burst time of process Enter name. burst time of process Enter name.

j. for(i=1.s.i<=m.i). for(i=1. scanf("%d".all[10][10].avail[10]. scanf("%d".i. int work[10]. } n1=0.j<=m.&m1).&all[i][j]).DEADLOCK AVOIDANCE – BANKER’S ALGORITHM #include<stdio.&avail[i]). printf("Enter no.&max[i][j].i<=m. . int main() { int m1. } for(i=1. } } for(i=1. scanf("%d".max[10][10]. } } printf("Which process wants to request resources:\n").j<=m.i++) { printf("Enter no. for(j=1. of instances of resource type %d available:\t". scanf("%d".j++) { need[i][j]= max[i][j]-all[i][j].i++) { for(j=1.h> #include<conio.p.&n).i++) { printf("\n").h> int n.k=0. } if(n1!=0) printf("\nIt will have to wait\n").j). int req[10].i). scanf("%d".i++) { if(req[i]>avail[i]) n1++.i<=m.&m). scanf("%d%d".i.i<=n.m. int check().j++) { printf("For process %d enter maximum and allocation criteria of resource %d". of resources:\n"). printf("Enter no. of processes:\n").i++) { printf("How many instances does it request of type %d:".n1.i<=n.&req[i]).finish[10].need[10][10]. for(i=1.

i<=m. int l.i++) { avail[i]=avail[i]-req[i]. need[m1][i]=need[m1][i]-req[i].i<=n. for(j=1. for(i=1.i++) finish[i]=0. all[m1][i]=all[m1][i]+req[i]. } if(p!=0) printf("\n---System is not in safe state (IT MUST WAIT)--").i<=m.j++) work[j]=work[j]+all[i][j]. } for(i=1. for(i=1.else { for(i=1.j<=m. return 0. } getch().i++) { if(finish[i]==0 && s==0) { k++. for(i=1.i++) work[i]=avail[i]. } int check() { s=0.i++) { if(finish[i]==0) p++. finish[i]=1. break.i<=n. else printf("\n---System is in safe state (Request can be granted)--").. for(. } } if(k==0) break.i<=n. .) { k=0. } p=0.

of resources: 3 For process 1 enter maximum and allocation criteria of resource 17 0 For process 1 enter maximum and allocation criteria of resource 24 1 For process 1 enter maximum and allocation criteria of resource 33 0 For process 2 enter maximum and allocation criteria of resource 13 2 For process 2 enter maximum and allocation criteria of resource 22 0 For process 2 enter maximum and allocation criteria of resource 32 0 For process 3 enter maximum and allocation criteria of resource 19 3 For process 3 enter maximum and allocation criteria of resource 20 0 For process 3 enter maximum and allocation criteria of resource 32 2 For process 4 enter maximum and allocation criteria of resource 12 2 For process 4 enter maximum and allocation criteria of resource 22 1 For process 4 enter maximum and allocation criteria of resource 32 1 For process 5 enter maximum and allocation criteria of resource 14 0 For process 5 enter maximum and allocation criteria of resource 23 0 For process 5 enter maximum and allocation criteria of resource 33 2 Enter no.for(l=1.l++) { if(need[i][l]<=work[l]) s=s. of instances of resource type 1 available: 10 Enter no. of instances of resource type 2 available: 5 Enter no. of instances of resource type 3 available: 7 Which process wants to request resources: 1 How many instances does it request of type 1:7 How many instances does it request of type 2:2 How many instances does it request of type 3:1 ---System is in safe state (Request can be granted)-- . of processes: 5 Enter no. } OUTPUT: Enter no.l<=m. } return s. else s=1.

} printf("Number of page faults : %d ".FIFO PAGE REPLACEMENT #include<stdio.h> #include<conio. flag2=0. if(top>=frsize) top=0.3. flag2=1.i<12. } void display() { . break. break.page[12]={2. for(i=0.5.j.i<3. } display(). int flag1=0. top++.i++) { if(fr[i]==page[j]) { flag1=1.1.5.i<frsize.flag2=0.j<12. getch().2}. } for(j=0.h> int fr[3]. for(i=0.j++) { flag1=0. int i.i++) { fr[i]=-1. pf++. void main() { void display().2.3.frsize=3. flag2=1.pf=0.2.i++) { if(fr[i]==-1) { fr[i]=page[j]. clrscr(). } } } if(flag2==0) { fr[top]=page[j]. } } if(flag1==0) { for(i=0.top=0.pf).2.5.4.

} OUTPUT: 2 -1 -1 2 2 2 5 5 5 5 3 3 3 3 3 -1 3 -1 3 3 2 2 2 2 2 5 5 1 1 1 4 4 4 4 4 2 : 6 Number of page faults . for(i=0.i<3. printf("\n").i++) printf("%d\t".int i.fr[i]).

k. int index.i++) { if(fr[i]==-1) { fr[i]=p[j].l.i.j++) { flag1=0.i++) { if(fs[i]==0) index=i. break.3.i++) fs[i]=0. for(i=0.5.k--) { for(i=0.fs[3]. break. } } for(i=0.j.i<3.frsize=3.5. for(k=j-1.3. for(i=0.i<3.i++) { fr[i]=-1. } } } if(flag2==0) { for(i=0.flag1=0.i++) { if(fr[i]==p[j]) { flag1=1. } } if(flag1==0) { for(i=0.2}.h> int fr[3].2.l++.h> #include<conio.2. } for(j=0.i++) { if(fr[i]==p[k]) fs[i]=1.LRU PAGE REPLACEMENT #include<stdio.flag2=0. void main() { void display().2.j<12.i<3.l<=frsize-1. .i<3.1.pf=0. clrscr().i<3.l=1.flag2=0.5. flag2=1.i<3. int p[12]={2.4. flag2=1.

for(i=0.} fr[index]=p[j]. pf++.i<3. } display().i++) printf("\t%d". } printf("\n no of page faults :%d".fr[i]). } void display() { int i.pf). getch(). printf("\n"). } OUTPUT: 2 -1 -1 2 2 2 2 2 2 2 3 3 3 3 3 -1 3 -1 3 5 5 5 5 5 5 5 5 1 1 1 4 4 4 2 2 2 no of page faults : 4 .

found=0. flag2=1. int p[12]={2.3.fs[3].5. } } if(flag1==0) { for(i=0.2.OPTIMAL PAGE REPLACEMENT #include<stdio. break.i<3. break.i++) { fr[i]=-1.lg[3].k++) { if(fr[i]==p[k]) { lg[i]=k-j.i<3.i++) { for(k=j+1. } } } if(flag2==0) { for(i=0.h> int fr[3].j<12.index.i. for(i=0.flag1=0. int max.pf=0.1. void main() { void display().k<12.h> #include<conio.5.flag2=0.k.3.i++) { if(fr[i]==-1) { fr[i]=p[j].i++) { if(fr[i]==p[j]) { flag1=1.2}.l.2. for(i=0.frsize=3.i<3. .j++) { flag1=0. flag2=0. } for(j=0.i++) lg[i]=0. flag2=1.2.i<3.j.4. clrscr(). break.5. for(i=0.i<frsize.

} } } found=0. for(i=0. } display().i<frsize. for(i=1. index=i. printf("\n"). index=0.fr[i]).i++) { if(max<lg[i]) { max=lg[i]. getch(). break.i<frsize. pf++. } printf("\n no of page faults:%d". } void display() { int i.i<3. } . for(i=0.i++) { if(lg[i]==0) { index=i. } } } fr[index]=p[j]. found=1.pf). } } if(found==0) { max=lg[0].i++) printf("\t%d".

OUTPUT: 2 -1 -1 2 3 -1 2 3 -1 2 3 1 2 3 5 2 3 5 4 3 5 4 3 5 4 3 5 2 3 5 2 3 5 2 3 5 no of page faults : 3 .

cout<<"\nEnter the free size of each block\n". getch().i++) cin>>list[i].". void addProcess(). break. of memory blocks". int top = 0.\n Press 2 : TO DELETE A PROCESS. case 3 : display(). cin >> choice. case 4 : exit(0). do{ cout<<"\n\n Press 1 : TO ADD A NEW PROCESS.i<n_blocks. return 0. top++. allocate(top-1).h> #include<process. break.BEST FIT #include<iostream. switch(choice) { case 1 : addProcess(). cin >> n_blocks. } void addProcess() { if(top<20) { cout<<"\nEnter the size of the process". cin >> id.".\n PRESS 3 : TO DISPLAY ALL THE PROCESS INFO. void get_blocks(). void display().p_list[2][20]. . void allocate(int x). void deleteProcess(int i).n_blocks. cin >> p_list[0][top]. get_blocks(). } }while(choice!=4). case 2 : cout<< "\nEnter the process id.\n Press 4 : TO EXIT. break.h> #include<conio. } void get_blocks() { cout<<"Enter the no. for(int i=0. deleteProcess(id-1).id. int main () { int choice.MEMORY MANAGEMENT.h> #include<stdio.h> using namespace std. int list[20].

return.".i++) cout<<i+1<<"\t\t"<<p_list[0][i]<<"\t\t"<<p_list[1][i]<<endl.num. } } if(small == 9999) { cout<<"Cannot allocate process".x.x++) { p_list[0][x]=p_list[0][x+1].pos.i<n_blocks. p_list[1][num]=pos+1. } void display() { cout<<"Process ID\tMemory needed\tMemory Block.\n".} else cout<<"Cannot enter a new process. } void deleteProcess(int i) { if(top==0) cout<<"No processes exist! Add some.small. cout<<"\nProcess "<<num+1<<" allocated to "<<"memory block "<<pos+1<<endl. pos = i. } } void allocate(int i) { int size. small = 9999.i++) { if(list[i]<small&&list[i]>=x) { small = list[i]. p_list[1][x]=p_list[1][x+1]. for(int x=i. x=p_list[0][i]. num=i. deleteProcess(num). } top--. for(int i=0. for(i=0.".i<top. Delete some first.x<top-1. } . } list[pos]-=x. else { list[p_list[1][i]-1]+=p_list[0][i].

3 Memory needed 90 TO TO TO TO Memory Block. DELETE A PROCESS. DISPLAY ALL THE PROCESS INFO. DISPLAY ALL THE PROCESS INFO.2 Enter the process id. EXIT. DELETE A PROCESS. DISPLAY ALL THE PROCESS INFO.OUTPUT: Enter the no.1 Enter the size of the process90 Process 1 allocated to memory block 2 Press Press PRESS Press 1 2 3 4 : : : : TO TO TO TO ADD A NEW PROCESS. EXIT.1 Press Press PRESS Press 1 2 3 4 : : : : TO TO TO TO ADD A NEW PROCESS. DISPLAY ALL THE PROCESS INFO.4 . of memory blocks3 Enter the free size of each block 300 100 200 Press Press PRESS Press 1 2 3 4 : : : : TO TO TO TO ADD A NEW PROCESS. DELETE A PROCESS. EXIT. DELETE A PROCESS. 2 Process ID 1 Press Press PRESS Press 1 2 3 4 : : : : ADD A NEW PROCESS. EXIT.

getch().\n PRESS 3 : TO DISPLAY ALL THE PROCESS INFO. switch(choice) { case 1 : addProcess(). int choice.id.h> using namespace std. do{ cout<<"\n\n Press 1 : TO ADD A NEW PROCESS.". void display().i<n_blocks. } }while(choice!=4).p_list[2][20]. break. void allocate(int x).h> #include<process. case 4 : exit(0). break. cout<<"\nEnter the free size of each block\n".i++) . int list[20]. of memory blocks". } void get_blocks() { cout<<"Enter the no. return 0. get_blocks(). int main () { clrscr().\n Press 2 : TO DELETE A PROCESS.n_blocks. cin >> n_blocks. cin >> choice. break. void addProcess().FIRST FIT #include<iostream. deleteProcess(id-1). int top = 0.\n Press 4 : TO EXIT. void get_blocks(). case 2 : cout<< "\nEnter the process id.h> #include<stdio. case 3 : display().h> #include<conio. cin >> id. for(int i=0.". void deleteProcess(int i).

} } if(flag == 0) { cout<<"Cannot allocate process". allocate(top-1).x<top-1. p_list[1][x]=p_list[1][x+1]. break. .".cin>>list[i]. } } void allocate(int i) { int size.num.pos. flag=0.flag. Delete some first.". cin >> p_list[0][top]. } else cout<<"Cannot enter a new process.i++) { if(list[i]>=x) { pos = i. for(int x=i. } top--. for(i=0. num=i.x++) { p_list[0][x]=p_list[0][x+1]. } void addProcess() { if(top<20) { cout<<"\nEnter the size of the process". flag=1. } void deleteProcess(int i) { if(top==0) cout<<"No processes exist! Add some. x=p_list[0][i]. else { list[p_list[1][i]-1]+=p_list[0][i].x. top++.i<n_blocks.

cout<<"\nProcess "<<num+1<<" allocated to "<<"memory block "<<pos+1<<endl.\n". } . } list[pos]-=x.i++) cout<<i+1<<"\t\t"<<p_list[0][i]<<"\t\t"<<p_list[1][i]<<endl. for(int i=0.i<top. p_list[1][num]=pos+1. return. } void display() { cout<<"Process ID\tMemory needed\tMemory Block.deleteProcess(num).

DISPLAY ALL THE PROCESS INFO.3 Memory needed Memory Block.2 Enter the process id.4 .1 Press Press PRESS Press 1 2 3 4 : : : : TO TO TO TO ADD A NEW PROCESS. DELETE A PROCESS.OUTPUT: Enter the no. EXIT. of memory blocks3 Enter the free size of each block 300 100 200 Press Press PRESS Press 1 2 3 4 : : : : TO TO TO TO ADD A NEW PROCESS. 100 1 Press Press PRESS Press 1 2 3 4 : : : : TO TO TO TO ADD A NEW PROCESS. DELETE A PROCESS. DELETE A PROCESS. DISPLAY ALL THE PROCESS INFO. EXIT. DELETE A PROCESS. DISPLAY ALL THE PROCESS INFO. EXIT. DISPLAY ALL THE PROCESS INFO. EXIT.1 Enter the size of the process100 Process 1 allocated to memory block 1 Press 1 : Press 2 : PRESS 3 : Press 4 : Process ID 1 TO TO TO TO ADD A NEW PROCESS.

void deleteProcess(int i).". int list[20]. case 4 : exit(0). int top = 0. cin >> n_blocks. void allocate(int x).". } void get_blocks() { cout<<"Enter the no.WORST FIT #include<iostream. break. for(int i=0.p_list[2][20].h> #include<process.\n Press 2 : TO DELETE A PROCESS. void addProcess().i++) cin>>list[i]. cin >> choice. deleteProcess(id-1).id. cout<<"\nEnter the free size of each block\n". switch(choice) { case 1 : addProcess(). case 2 : cout<< "\nEnter the process id. int main () { int choice. break.n_blocks. do{ cout<<"\n\n Press 1 : TO ADD A NEW PROCESS. getch(). void get_blocks(). } void addProcess() . get_blocks(). cin >> id.h> #include<stdio. case 3 : display().h> #include<conio.\n Press 4 : TO EXIT. } }while(choice!=4). return 0.h> //using namespace std. void display(). of memory blocks".\n PRESS 3 : TO DISPLAY ALL THE PROCESS INFO. break.i<n_blocks.

.". allocate(top-1). } } if(large == -1) { cout<<"Cannot allocate process". Delete some first. } else cout<<"Cannot enter a new process.i++) { if(list[i]>large&&list[i]>=x) { large = list[i]. return. } list[pos]-=x.num. for(int x=i. num=i. p_list[1][x]=p_list[1][x+1]. for(i=0. cin >> p_list[0][top]. large = -1.i<n_blocks. top++.x. else { list[p_list[1][i]-1]+=p_list[0][i].large.".pos. } void deleteProcess(int i) { if(top==0) cout<<"No processes exist! Add some. } top--. } } void allocate(int i) { int size. pos = i. deleteProcess(num).x++) { p_list[0][x]=p_list[0][x+1].{ if(top<20) { cout<<"\nEnter the size of the process". x=p_list[0][i].x<top-1.

2 Enter the process id. Press 2 : TO DELETE A PROCESS. DELETE A PROCESS. } void display() { cout<<"Process ID\tMemory needed\tMemory Block. DELETE A PROCESS. DISPLAY ALL THE PROCESS INFO. PRESS 3 : TO DISPLAY ALL THE PROCESS INFO. DISPLAY ALL THE PROCESS INFO. EXIT. p_list[1][num]=pos+1. 50 1 Press Press PRESS Press 1 2 3 4 : : : : TO TO TO TO ADD A NEW PROCESS. for(int i=0. EXIT. } OUTPUT: Enter the no.\n". DISPLAY ALL THE PROCESS INFO. EXIT.i<top.i++) cout<<i+1<<"\t\t"<<p_list[0][i]<<"\t\t"<<p_list[1][i]<<endl.1 Press 1 : TO ADD A NEW PROCESS.3 Memory needed Memory Block. .cout<<"\nProcess "<<num+1<<" allocated to "<<"memory block "<<pos+1<<endl. of memory blocks3 Enter the free size of each block 300 100 200 Press Press PRESS Press 1 2 3 4 : : : : TO TO TO TO ADD A NEW PROCESS. DELETE A PROCESS.1 Enter the size of the process50 Process 1 allocated to memory block 1 Press 1 : Press 2 : PRESS 3 : Press 4 : Process ID 1 TO TO TO TO ADD A NEW PROCESS.

. Press Press PRESS Press 1 2 3 4 : : : : TO TO TO TO ADD A NEW PROCESS.Press 4 : TO EXIT.3 Process ID Memory needed Memory Block. DISPLAY ALL THE PROCESS INFO. DELETE A PROCESS. EXIT.

Sign up to vote on this title
UsefulNot useful