Tuesday, 19 November 2013

INTERPROCESS COMMUNICATION USING PIPES

PROGRAM

#include<unistd.h>
#include<stdio.h>
int main()
{
char a[10];
int pipe_pointer[2];
pid_t child;
char message[50];
pipe(pipe_pointer);
child=fork();
if(child==0)
{
printf("\n CHILD PROCESS IS WRITING!!! ");
printf(“\n Enter the string’);
scanf(“%s”,a);
close(pipe_pointer[0]);
write(pipe_pointer[1],a,sizeof(a));
}
else
{
printf(“ PARENT PROCESS IS READING”);
close(pipe_pointer[1]);
read(pipe_pointer[0],message,sizeof(message));
printf(“\n The parent has read    :\n % s”,message);
}
close(pipe_pointer[0]);
close(pipe_pointer[1]);
}       
    

Goto texteditor then type this program





Now open terminal type this to get output



gcc pipes.c
./a.out 

0 Comments:

Post a Comment

Facebook Twitter Delicious Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes