WAP TO IMPLEMENT HAUNG’S TERMINATION DETECTION
#include<stdio.h>
#include<conio.h>
void main()
{
double p[3];
double c=1;
int k,j,res,res1,i,now,now1,con;
clrscr();
for(i=0;i<3;i++)
{
p[i]=0;
}
printf("\nWhich process do you want to start?\n");
k=0;
printf("p[%d] OR p[%d] OR p[%d]",k,k+1,k+2);
printf("\nenter the process no.(0/1/2):\n");
scanf("%d",&j);
p[j]=0.5;
c=c-p[j];
printf("\nDoes process C(controller)invokes any other process:\nFor Yes-Press 1\nFor No-press 0\n");
scanf("%d",&res);
if(res==1)
{
printf("\nWhich process will it invoke(1 OR 2):\n");
scanf("%d",&now);
p[now]=0.25;
c=c-0.25;
}
printf("\nDoes process C(controller)invokes any other process:\nFor Yes-Press 1\nFor No-press 0\n");
scanf("%d",&res1);
if(res1==1)
{
printf("\nWill it invoke(1 OR 2):\n");
p[now1]=0.25;
c=c-0.25;
}
for(i=0;i<3;i++)
{
printf("\nIs Process p[%d] is completed:?\nfor yes-press 1\nfor No-press 0\n",i);
scanf("%d",&con);
if(con==1)
{
c=c+p[i];
}
}
if(c==1)
{
printf("\nAll Processes are COMPLETED");
}
else
{
printf("\nSome PROCESS is NOT Complete");
}
getch();
}
Output:-
WRITE A PROGRAM TO IMPLEMENT EDGE CHASING DEADLOCK DETECTION ALGORITHM
#include<stdio.h>
#include<conio.h>
void main()
{
int d[7][7];
int i,j,n,a;
int res;
clrscr();
printf("Enter the number of nodes\n\n");
scanf("%d",&n);
printf("Enter the elements of Dependency matrix");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&d[i][j]);
}
}
d[0][1]=1;
d[1][2]=1;
d[2][3]=1;
printf("DEPENDECNY MATRIS IS:\n");
for(i=0;i<n;i++)
{ for(j=0;j<n;j++)
{
printf("%d",d[i][j]);
}
}
getch();
}
Output:-
WAP TO IMPLEMENT FIRST IN FIRST OUT ALGORITHM FOR CPU SCHEDULING
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],i,n,j,b[20],waiting[20],position,tt[20],swap,p[20],swap_1;
clrscr();
printf("Enter the number of process");
scanf("%d",&n);
printf("Enter the arrival time");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
p[i]=i+1;
}
printf("Enter the burst time");
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<(n-1);i++)
{
position=i;
for(j=i+1;j<n;j++)
{
if(a[position]>a[j])
position=j;
}
if(position!=i)
{
swap=a[i];
a[i]=a[position];
a[position]=swap;
swap_1=p[i];
p[i]=p[position];
p[position]=swap_1;
}
}
waiting[0]=0;
tt[0]=4;
for(i=1;i<n;i++)
{
tt[i]=tt[i-1]+b[i];
}
for(i=1;i<n;i++)
{
waiting[i]=tt[i-1]-a[i];
}
printf("\nP_Id Arrival time\t Waiting time \t Burst time \t Turnaround time");
for(i=0;i<n;i++)
{
printf("\nP%d",p[i]);
printf("\t%d",a[i]);
printf("\t\t %d",waiting[i]);
printf("\t\t %d",b[i]);
printf("\t\t\t%d",tt[i]);
}
printf("\n\n total turnaround time %d",tt[n]);
getch();
}
Output:-
WAP TO IMPLEMENT LAMPORT LOGICAL CLOCK
#include<stdio.h>
#include<conio.h>
int maxx(int,int,int);
void main()
{
int i;
int d=1;
int p1[4];
int p2[3];
int p3[4];
p1[1]=1;
p2[1]=1;
p3[1]=1;
clrscr();
for(i=1;i<=4;i++)
{
if(i>1)
{
p1[i]=p1[i-1]+d;
}
}
for(i=1;i<=4;i++)
{
if(i>1)
{
p3[i]=p3[i-1]+d;
}
}
for(i=1;i<=3;i++)
{
if(i==2)
{
p2[i]=maxx(p1[2],p2[1],p3[1])+d;
}
else if(i==3)
{
p2[i]=maxx(p1[3],p2[2],p3[4])+d;
}
}
printf("\nClock values are:\nP1:");
for(i=1;i<=4;i++)
{
printf("\t%d",p1[i]);
}
printf("\nP2:");
for(i=1;i<=3;i++)
{
printf("\t%d",p2[i]);
}
printf("\nP3:");
for(i=1;i<=4;i++)
{
printf("\t%d",p3[i]);
}
getch();
}
int maxx(int p,int q,int r)
{
if(p>q)
{
if(p>r)
{
return(p);
}
else
{
return(r);
}
}
else
{
if(q>r)
{
return(q);
}
else
{
return(r);
}
}
}
Output:-
WAP TO IMPLEMENT LAMPORT NON TOKEN BASED MUTUAL EXCLUSION ALGORITHM
#include<stdio.h>
#include<conio.h>
void main()
{
int s[10],n,i,ch=1,temp,j;
printf("\n enter the number of sites");
scanf("\n %d",&n);
for (i=0;i<n;i++)
{
printf("\n enter the timestamp of %d process",i+1);
scanf("%d",&s[i]);
}
for(i=0;i<n;i++)
{
for(j=n-1;j>=i+1;j--)
{
if(s[j]<s[j-1])
{
temp=s[j];
s[j]=s[j-1];
s[j-1]=temp;
}
}
}
for(i=0;i<n;i++)
printf("\n %d",s[i]);
while(ch!=0)
{
printf("\n enter the choice");
printf("\n 1.reqesting a critical section");
printf("\n 2. releasing a critical section");
printf("\n 0.exit");
scanf("\n %d",&ch);
switch(ch)
{
case 1 :
printf("\n enter the timestamp");
scanf("\n %d",&s[n]);
n++;
for(i=0;i<n;i++)
{
for(j=n;j>=i+1;j--)
{
if(s[j]>s[j+1])
{
temp=s[j];
s[i]=s[j+1];
s[j+1]=temp;
}
}
}
for(i=0;i<n;i++)
printf("\n %d",s[i]);
break;
case 2:
s[n]=0;
n--;
}
}
getch();
}
Output:-
I really enjoy reading and also appreciate your work.
ReplyDeletec++ programming