Join With Me...

3:11 AM

Pipes in Unix IPC

#include
main()
{
clock_t st,en;
int a[2],i,b[2],c[2],s[]={1,2,3,4,5,6,7,8,9,10},temp=0;
int p,res=0,res1=0,n;
printf("Enter The Total Elements\n");
scanf("%d",&n);
printf("Enter All Elements One By One\n");
for(i=0;i
scanf("%d",(s+i));
//st=clock();
//printf("\nSTART IS :%d",st);
if(n%2==1)
{
n++;
*(s+i)=0;
}
pipe(a);
pipe(b);
p=fork();
for(i=0;i
if(p>0)
{
write(a[1],(s+i),1);
read(b[0],&temp,1);
res=res+temp;
}
else
{
read(a[0],&res1,1);
res=*(s+i+1)+res1;
write(b[1],&res,1);
}
printf("\nRES :%d",res);
en=clock();
printf("\nTOTAL TIME IS : %d ",(en-st));
}


0 comments:

Post a Comment