Os & Cn

  • Uploaded by: rama chandra
  • 0
  • 0
  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Os & Cn as PDF for free.

More details

  • Words: 1,686
  • Pages: 26
********************************************************* 1 .PROGRAM FOR BIT STUFFING ********************************************************* #include<stdio.h> #include #include<string.h> void main() { int a[20],b[30],i,j,k,count,n; clrscr(); printf("Enter frame length:"); scanf("%d",&n); printf("Enter input frame (0's & 1's only):"); for(i=0;i
getch(); } OUTPUT: Enter frame length: 10 Enter input frame (0's & 1's only): 1010111111 After stuffing the frame is: 10101111101 *********************************************************** 2.PROGRAM FOR CHARACTER STUFFING *********************************************************** #include<stdio.h> #include #include<string.h> #include<process.h> void main() { int i=0,j=0,n,pos; char a[20],b[50],ch; clrscr(); printf("enter string\n"); scanf("%s",&a); n=strlen(a); printf("enter position\n"); scanf("%d",&pos); if(pos>n) { printf("invalid position, Enter again :"); scanf("%d",&pos); } printf("enter the character\n"); ch=getche(); b[0]='d'; b[1]='l'; b[2]='e'; b[3]='s';

b[4]='t'; b[5]='x'; j=6; while(i
invalid position,enter again: 3 enter the character: k OUTPUT: String after stuffing: dlestx as dle k dle dle dlefgh dleetx ***************************************************** 3 . PROGRAM FOR FINDING REMAINDER: ******************************************************* #include<stdio.h> #include void main() { int i,j,gen[4],rem[4],frl=8,genl=4,k,k1,fr[11]; clrscr(); printf("enter frame:"); for(i=0;i
fr[k1]=rem[i]; k1++; } } } printf("\nremainder is: "); for(i=0;i<4;i++) printf("%d",rem[i]); getch(); } OUTPUT: enter frame: 10110100 enter generator: 1010 remainder is: 0010 ********************************************************** 4 .PROGRAM FOR CYCLIC REDUNDENCY CHECK ************************************************************* #include<stdio.h> #include int gen[4],genl,frl,rem[4]; void main() { int i,j,fr[8],dupfr[11],recfr[11],tlen,flag; clrscr(); frl=8; genl=4; printf("enter frame:"); for(i=0;i
dupfr[i]=0; } remainder(dupfr); for(i=0;i
} for(i=0;i
************************************************************* 5 .PROGRAM FOR FINDING SHORTEST PATH FOR A GIVEN GRAPH ************************************************************* #include<stdio.h> #include void main() { int path[5][5],i,j,min,a[5][5],p,st=1,ed=5,stp,edp,t[5],index; clrscr(); printf("enter the cost matrix\n"); for(i=1;i<=5;i++) for(j=1;j<=5;j++) scanf("%d",&a[i][j]); printf("enter the paths\n"); scanf("%d",&p); printf("enter possible paths\n"); for(i=1;i<=p;i++) for(j=1;j<=5;j++) scanf("%d",&path[i][j]); for(i=1;i<=p;i++)

{ t[i]=0; stp=st; for(j=1;j<=5;j++) { edp=path[i][j+1]; t[i]=t[i]+a[stp][edp]; if(edp==ed) break; else stp=edp; } } min=t[st];index=st; for(i=1;i<=p;i++) { if(min>t[i]) { min=t[i]; index=i; } } printf("minimum cost %d",min); printf("\n minimum cost path "); for(i=1;i<=5;i++) { printf("--> %d",path[index][i]); if(path[index][i]==ed) break; } getch(); } OUTPUT: 1

1 4

2

2 3

2 3

4

3 5

5

enter the cost matrix : 01420 00023 00030 00005 00000 enter number of paths : 4 enter the paths : 12450 12500 14500 13450 minimum cost : 4 minimum cost path : 1 2 5 ************************************************************ 6. PROGRAM FOR FCFS CPU SCHEDULING ALGORITHM ************************************************************ #include<stdio.h> #include #include<process.h> void main() { char p[10][5]; int tot=0,wt[10],i,n; float avg=0; clrscr(); printf("enter no of processes:"); scanf("%d",&n); for(i=0;i
wt[i]=wt[i-1]+et[i-1]; tot=tot+wt[i]; } avg=(float)tot/n; printf("p_name\t P_time\t w_time\n"); for(i=0;i
0 4 7 9 14

************************************************************ 7. PROGRAM FOR SJF CPU SCHEDULING ALGORITHM ************************************************************ #include<stdio.h> #include #include<process.h> void main() {

char p[10][5],temp[5]; int tot=0,wt[10],pt[10],i,j,n,temp1; float avg=0; clrscr(); printf("enter no of processes:"); scanf("%d",&n); for(i=0;ipt[j]) { temp1=pt[i]; pt[i]=pt[j]; pt[j]=temp1; strcpy(temp,p[i]); strcpy(p[i],p[j]); strcpy(p[j],temp); } } } wt[0]=0; for(i=1;i
OUTPUT: enter no of processes: 5 enter process1 name: aaa enter process time: 4 enter process2 name: bbb enter process time: 3 enter process3 name: ccc enter process time: 2 enter process4 name: ddd enter process time: 5 enter process5 name: eee enter process time: 1 p_name

P_time

eee 1 ccc 2 bbb 3 aaa 4 ddd 5 total waiting time=20 avg waiting time=4.00

w_time 0 1 3 6 10

************************************************************* 8. PROGRAM FOR PRIORITY CPU SCHEDULING ALGORITHM ************************************************************* #include<stdio.h> #include void main() { char p[10][5],temp[5]; int i,j,pt[10],wt[10],totwt=0,pr[10],temp1,n; float avgwt; clrscr(); printf("enter no of processes:"); scanf("%d",&n); for(i=0;i
scanf("%d",&pt[i]); printf("enter priority:"); scanf("%d",&pr[i]); } for(i=0;ipr[j]) { temp1=pr[i]; pr[i]=pr[j]; pr[j]=temp1; temp1=pt[i]; pt[i]=pt[j]; pt[j]=temp1; strcpy(temp,p[i]); strcpy(p[i],p[j]); strcpy(p[j],temp); } } } wt[0]=0; for(i=1;i
enter process time: 4 enter priority:5 enter process2 name: bbb enter process time: 3 enter priority:4 enter process3 name: ccc enter process time: 2 enter priority:3 enter process4 name: ddd enter process time: 5 enter priority:2 enter process5 name: eee enter process time: 1 enter priority:1 p_name eee ddd ccc bbb aaa

P_time 1 5 2 3 4

priority 1 2 3 4 5

w_time 0 1 6 8 11

total waiting time=26 avg waiting time=5.20 ****************************************************** 9. PROGRAM FOR ROUND ROBIN CPU SCHEDULING ALGORITHM ********************************************************** #include<stdio.h> #include #include<process.h> #include<string.h> void main() { char p[10][5]; int et[10],wt[10],timer=3,count,pt[10],rt,i,j,totwt=0,t,n=5,found=0,m; float avgwt; clrscr(); for(i=0;i
printf("enter the process name : "); scanf("%s",&p[i]); printf("enter the processing time : "); scanf("%d",&pt[i]); } m=n; wt[0]=0; i=0; do { if(pt[i]>timer) { rt=pt[i]-timer; strcpy(p[n],p[i]); pt[n]=rt; et[i]=timer; n++; } else { et[i]=pt[i]; } i++; wt[i]=wt[i-1]+et[i-1]; }while(i
found=0; } } for(i=0;i<m;i++) { totwt+=wt[i]; } avgwt=(float)totwt/m; for(i=0;i<m;i++) { printf("\n%s\t%d\t%d",p[i],pt[i],wt[i]); } printf("\ntotal waiting time %d\n",totwt); printf("total avgtime %f",avgwt); } INPUT : enter the process name : aaa enter the processing time : 4 enter the process name : bbb enter the processing time : 3 enter the process name : ccc enter the processing time : 2 enter the process name : ddd enter the processing time : 5 enter the process name : eee enter the processing time : 1 OUTPUT : p_name aaa bbb ccc ddd eee

p_time 4 3 2 5 1

w_time 9 3 6 10 11

total waiting time : 39 average waiting time : 7.8000 ************************************************************ 10. PROGRAM FOR FIFO PAGE REPLACEMENT ALGORITHM *************************************************************

#include<stdio.h> #include int fr[3]; void main() { void display(); int i,j,page[12]={2,3,2,1,5,2,4,5,3,2,5,2}; int flag1=0,flag2=0,pf=0,frsize=3,top=0; clrscr(); for(i=0;i<3;i++) { fr[i]=-1; } for(j=0;j<12;j++) { flag1=0; flag2=0; for(i=0;i<12;i++) { if(fr[i]==page[j]) { flag1=1; flag2=1; break; } } if(flag1==0) { for(i=0;i
if(top>=frsize) top=0; } display(); } printf("Number of page faults : %d ",pf); getch(); } void display() { int i; printf("\n"); for(i=0;i<3;i++) printf("%d\t",fr[i]); } OUTPUT : 2 -1 -1 2 3 -1 2 3 -1 2 3 1 5 3 1 5 2 1 5 2 4 5 2 4 3 2 4 3 2 4 3 5 4 3 5 2 Number of page faults : 6 ************************************************************ 11. PROGRAM FOR LRU PAGE REPLACEMENT ALGORITHM ************************************************************ #include<stdio.h> #include int fr[3]; void main() { void display(); int p[12]={2,3,2,1,5,2,4,5,3,2,5,2},i,j,fs[3]; int index,k,l,flag1=0,flag2=0,pf=0,frsize=3; clrscr();

for(i=0;i<3;i++) { fr[i]=-1; } for(j=0;j<12;j++) { flag1=0,flag2=0; for(i=0;i<3;i++) { if(fr[i]==p[j]) { flag1=1; flag2=1; break; } } if(flag1==0) { for(i=0;i<3;i++) { if(fr[i]==-1) { fr[i]=p[j]; flag2=1; break; } } } if(flag2==0) { for(i=0;i<3;i++) fs[i]=0; for(k=j-1,l=1;l<=frsize-1;l++,k--) { for(i=0;i<3;i++) { if(fr[i]==p[k]) fs[i]=1; } } for(i=0;i<3;i++) { if(fs[i]==0)

index=i; } fr[index]=p[j]; pf++; } display(); } printf("\n no of page faults :%d",pf); getch(); } void display() { int i; printf("\n"); for(i=0;i<3;i++) printf("\t%d",fr[i]); } OUTPUT : 2 -1 -1 2 3 -1 2 3 -1 2 3 1 2 5 1 2 5 1 2 5 4 2 5 4 3 5 4 3 5 2 3 5 2 3 5 2 no of page faults : 4 ************************************************************* 12. PROGRAM FOR OPTIMAL PAGE REPLACEMENT ALGORITHM ************************************************************* #include<stdio.h> #include int fr[3]; void main() { void display();

int p[12]={2,3,2,1,5,2,4,5,3,2,5,2},i,j,fs[3]; int max,found=0,lg[3],index,k,l,flag1=0,flag2=0,pf=0,frsize=3; clrscr(); for(i=0;i<3;i++) { fr[i]=-1; } for(j=0;j<12;j++) { flag1=0; flag2=0; for(i=0;i<3;i++) { if(fr[i]==p[j]) { flag1=1; flag2=1; break; } } if(flag1==0) { for(i=0;i<3;i++) { if(fr[i]==-1) { fr[i]=p[j]; flag2=1; break; } } } if(flag2==0) { for(i=0;i<3;i++) { lg[i]=0; } for(i=0;i
lg[i]=k-j; break; } } } found=0; for(i=0;i
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 *********************************************************** 13. PROGRAM FOR DEADLOCK DETECTION ALGORITHM ************************************************************ #include<stdio.h> #include void main() { int found,flag,l,p[4][5],tp,c[4][5],i,j,k=1,m[5],r[5],a[5],temp[5],sum=0; clrscr(); printf("enter total no of processes"); scanf("%d",&tp); printf("enter clain matrix"); for(i=1;i<=4;i++) for(j=1;j<=5;j++) { scanf("%d",&c[i][j]); } printf("enter allocation matrix"); for(i=1;i<=4;i++) for(j=1;j<=5;j++) { scanf("%d",&p[i][j]); } printf("enter resource vector:\n"); for(i=1;i<=5;i++) { scanf("%d",&r[i]); }

printf("enter availability vector:\n"); for(i=1;i<=5;i++) { scanf("%d",&a[i]); temp[i]=a[i]; } for(i=1;i<=4;i++) { sum=0; for(j=1;j<=5;j++) { sum+=p[i][j]; } if(sum==0) { m[k]=i; k++; } } for(i=1;i<=4;i++) { for(l=1;ltemp[j]) { flag=0; break; } } if(flag==1) { m[k]=i; k++; for(j=1;j<=5;j++) temp[j]+=p[i][j]; } } printf("deadlock causing processes are:"); for(j=1;j<=tp;j++) {

found=0; for(i=1;i

Related Documents

Os & Cn
November 2019 10
Cn
April 2020 30
Cn
November 2019 38
Cn
November 2019 51
Cn
November 2019 56
Cn
October 2019 50

More Documents from ""

Bankers Algorithm Program
November 2019 13
Os & Cn
November 2019 10
Introuction To C# Lesson 0
November 2019 15
Archagam_4
October 2019 53
Badan Eksaminatif.docx
June 2020 34
Archagam_3
October 2019 51