Thursday 29 September 2011


IMPLEMENTATION OF INTERPROCESS COMMUNICATION USING PIPES

AIM:
            To implement interprocess communication using pipes.

ALGORITHM:

1. Start the process.
2. Create a child process using fork().
3. Now close the read end of the parent using close().
4. Write the data in the pipe using write().
5. Now close the read end of the child using close().
6. Read the data in the pipe using read().
7. Display the string.
8. Stop the process.

PROGRAM:

#include<stdio.h>
int main()
{
int fd[2],child;
char a[10];
printf(“Enter the string to enter into the pipe:\t”);
scanf(“%s”, a);
pipe(fd);
child=fork();
if(!child)
{
close(fd[0]);
write(fd[1],a,5);
wait(0);
}
else
{
close(fd[1]);
read(fd[0],a,5);
printf(“The string received from the pipe is %s”, a);
}
return 0;
}

OUTPUT:

[root@localhost ~]# ./pipes

Enter the string to enter into the pipe: Welcome

The string retrieved from the pipe is Welcome

RESULT:
Thus the program is executed and the output  is verified.

0 comments:

Post a Comment