Join With Me...

3:10 AM

Sort program in C using Unix IPC fork and pipe

main()
{
void sort(int *,int);
int n,arr[10],i;
printf("Enter The Total Elements\n");
scanf("%d",&n);
printf("Enter Elements One By One\n");
for(i=0;i
scanf("%d",(arr+i));
sort(arr,n);
}

void sort(int *s,int n)
{
int a[2],i=0,b[2],c[2],temp=0;
int p,sec=0,j,fir=0;
int max=*(s+i);
if (n%2)
*(s+n)=0;
pipe(a);
pipe(b);
p=fork();
{
for(i=0;i
if(p>0)
{
write(a[1],&max,1);
read(b[0],&max,1);
if(max<*(s+i))
max=*(s+i);
printf("\nCHILD: %d ",max);
}
else
{
sec=*(s+i+1);
read(a[0],&max,1);
if(max
max=sec;
write(b[1],&max,1);
printf("\nPARENT: %d",max);
}
}
printf("\nMAXIMUM IS :%d SEC: %d",max,sec);
}


0 comments:

Post a Comment