/*CSEMATTER.BLOGSPOT.IN
Program-to implement concurrent checkpoint*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
void delay(unsigned int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock());
}
int main()
{
int pr[10],p[10],n,i,j,count,temp;
printf("Enter the no. of processes: ");
scanf("%d",&n);
for(i=0; i<n; i++)
p[i]=i+1;
printf("Enter the priority of processes \n");
for(i=0; i<n; i++)
{
printf("Priority of process P%d : \n",i+1);
scanf("%d",&pr[i]);
}
for(i=0; i<n-1; i++)
{
for(j=i+1; j<n; j++)
{
if(pr[i]>pr[j])
{
temp=pr[i];
pr[i]=pr[j];
pr[j]=temp;
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
}
}
for(i=0; i<n; i++)
{
count=0;
for(j=0; j<n; j++)
{
if(i!=j)
printf("P%d is sending request to P%d \n",p[i],p[j]);
else
continue;
}
for(j=0; j<n; j++)
{
if(i!=j)
{
printf("P%d is sending ack to P%d \n",p[j],p[i]);
count++;
}
else
continue;
}
if(count==n-1)
{
printf("Ack from all the processes has been received \n");
printf("P%d is forming a Consistent Checkpoint point \n",p[i]);
delay(10000);
for(j=0; j<n; j++)
{
if(i!=j)
printf("P%d sending release msg to P%d \n",p[i],p[j]);
else
continue;
}
printf("\n \n");
}
else
printf("Ack from all the processes not received hence Process P%d cann't form a consistent checkpoint \n \n",p[i]);
}
getch();
}
/* OUTPUT:
Enter the no. of processes: 3
Enter the no. of processes: 3
Enter the priority of processes
Priority of process P1 :
3
Priority of process P2 :
2
Priority of process P3 :
1
P3 is sending request to P2
P3 is sending request to P1
P2 is sending ack to P3
P1 is sending ack to P3
Ack from all the processes has been received
P3 is forming a Consistent Checkpoint point
P3 sending release msg to P2
P3 sending release msg to P1
P2 is sending request to P3
P2 is sending request to P1
P3 is sending ack to P2
P1 is sending ack to P2
Ack from all the processes has been received
P2 is forming a Consistent Checkpoint point
P2 sending release msg to P3
P2 sending release msg to P1
P1 is sending request to P3
P1 is sending request to P2
P3 is sending ack to P1
P2 is sending ack to P1
Ack from all the processes has been received
P1 is forming a Consistent Checkpoint point
P1 sending release msg to P3
P1 sending release msg to P2 */